替換所有與該字段值,相關的表!

2021-06-15 18:31:34 字數 1361 閱讀 7512

declare @oldstr varchar(100)

set @oldstr='原字串'  --原字元

declare @newstr varchar(100)

set @newstr='新字串'  --新字元

declare @s varchar(8000)

declare tb cursor local for

select s='if exists(select 1 from ['+b.name+'] where ['+a.name+'] like ''%'+@oldstr+'%'')

update ['+b.name+'] set ['+a.name+']='''+@newstr+''' where ['+a.name+']='''+@oldstr+''' '

from syscolumns a join sysobjects b on a.id=b.id

where b.xtype='u' and a.status>=0

and a.xusertype in(175,239,231,167)

open tb

fetch next from tb into @s

while @@fetch_status=0

begin

exec(@s)

fetch next from tb into @s

endclose tb

deallocate tb

給定乙個任意的字段的值,查詢出它屬於的表及哪個欄位的sql語句:

declare @str varchar(100)

set @str='ph'  --要搜尋的字串

declare @s varchar(8000)

declare tb cursor local for

select s='if exists(select 1 from ['+b.name+'] where ['+a.name+'] like ''%'+@str+'%'')

print ''所在的表及字段: ['+b.name+'].['+a.name+']'''

from syscolumns a join sysobjects b on a.id=b.id

where b.xtype='u' and a.status>=0

and a.xusertype in(175,239,231,167)

open tb

fetch next from tb into @s

while @@fetch_status=0

begin

exec(@s)

fetch next from tb into @s

endclose tb

deallocate tb

mysql遍歷所有表字段替換值

update eform lf directory set directory name 集團總部 where directory name 集團 update eform lf directory set directory name replace directory name,集團 集團總部 ...

sql字段值的替換

資料庫有一張表bug 缺陷記錄表 裡面有欄位severity 嚴重程度 severity的值實際為1,2,3,4,但希望在查詢結果中將severity的1,2,3,4值顯示為其他的值,但severity的實際值不會改變 例如 資料表的結構和資料如下 bug id name severity 1 張三...

查出所有字段預設值的相關資訊

以系統自帶pubs資料庫為例.這個語句可以查出所有預設值的相關資訊.htl258 tony 2009 04 16 02 53 select select name from sysobjects where id c.id 表名,select name from syscolumns where c...