修改数据库中所有表中包含某个字段名的值
Posted 不懂事的小男孩
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了修改数据库中所有表中包含某个字段名的值相关的知识,希望对你有一定的参考价值。
1、查询包含某字段的所有表 select object_name(id) objName,Name as colName from syscolumns where (name like‘%你要查询的字段名%‘) and id in(select id from sysobjects where xtype=‘u‘) order by objname ; 2、查询包含某字段的所有存储过程 SELECT obj.Name 存储过程名, sc.TEXT 存储过程内容 FROM syscomments sc INNER JOIN sysobjects obj ON sc.Id = obj.ID WHERE sc.TEXT LIKE ‘%你要查询的字段名%‘
declare @verId UNIQUEIDENTIFIER=‘xxxxx‘ BEGIN SET NOCOUNT ON; DECLARE @sql NVARCHAR(max) DECLARE cursorClearUserData CURSOR LOCAL FOR SELECT 表名 = D.name FROM syscolumns A LEFT JOIN systypes B ON A.xusertype=B.xusertype INNER JOIN sysobjects D ON A.id=D.id and D.xtype=‘U‘ and D.name<>‘dtproperties‘ LEFT JOIN sys.extended_properties g ON a.id=g.major_id AND a.colid=g.minor_id WHERE A.name= ‘IsUser‘ ORDER BY D.name ; OPEN cursorClearUserData DECLARE @tableName NVARCHAR(100); FETCH NEXT FROM cursorClearUserData INTO @tableName WHILE @@FETCH_STATUS = 0 BEGIN SET @sql = ‘update ‘ + @tableName + ‘ set IsUser= 0 where Pro_PrVeId=‘+ ‘‘‘‘+CAST(@verId AS NVARCHAR(36)) + ‘‘‘‘+‘;‘ print @tableName FETCH NEXT FROM cursorClearUserData INTO @tableName END CLOSE cursorClearUserData DEALLOCATE cursorClearUserData SET NOCOUNT OFF; END
以上是关于修改数据库中所有表中包含某个字段名的值的主要内容,如果未能解决你的问题,请参考以下文章
mysql语句 修改表某个字段的值为 另一个表的值!~求帮助!~急急!