怎么删除mysql数据库中某表中的某个字段的数据?

怎么删除mysql数据库中某表中的某个字段的数据?,第1张

表名 table_name      要 *** 作的 字段名  field_name

如果删除字段的值,可以将所有值清空:

如果删除字段(这个字段从此就没有了):

基本的语法为:alter table <表名>drop column <字段名>

1.增加一个字段

2.删除一个字段

3.修改一个字段

http://blog.csdn.net/qustdjx/article/details/8875827

表名 table_name

要 *** 作的字段名 field_name

如果删除字段的值,可以将所有值清空:

UPDATE table_name SET field_name = ''

如果删除字段(这个字段从此就没有了):

ALTER TABLE table_name DROP COLUMN field_name

--先备份一下数据库。

 

--用游标

declare @str varchar(100) ,@tb varchar(100),@col varchar(20)

--定义游标

declare DZCursor CURSOR for 

SELECT b.name,a.name FROM syscolumns a,sysobjects b where a.id=b.id and b.xtype='u' and b.name like 'tab%' and a.xtype in (167,231)

--打开游标

open  DZCursor 

--从游标取记录

fetch next from DZCursor into @tb, @col

--当有记录

while @@fetch_status=0 

begin 

exec ('update '+@tb+' set '+@col+'=null')

--取下一条记录

fetch next from DZCursor into @tb, @col 

end 

--关闭游标

close DZCursor 

--删除游标引用

deallocate DZCursor


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/6426113.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-22
下一篇 2023-03-22

发表评论

登录后才能评论

评论列表(0条)

保存