码迷,mamicode.com
首页 > 数据库 > 详细

修改数据库中所有表中包含某个字段名的值

时间:2020-01-09 11:49:04      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:oca   arp   comment   left join   eal   tab   order by   cas   nts   

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

  

修改数据库中所有表中包含某个字段名的值

标签:oca   arp   comment   left join   eal   tab   order by   cas   nts   

原文地址:https://www.cnblogs.com/daizhipeng/p/12170604.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!