gpt4 book ai didi

SQL - 查询以在数据库的所有表中查找特定列但没有空值

转载 作者:行者123 更新时间:2023-12-02 01:37:27 24 4
gpt4 key购买 nike

我不是 SQL 专家。我需要搜索存在于数据库所有表中但没有为该特定记录存储空值的列。

下面是获取所有具有我的列名的表的查询:

SELECT TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE column_name LIKE 'classPK'

最佳答案

试试这个...

declare @q nvarchar(1000);
declare cur_Select cursor for
select 'select * from ['+tab.name+'] where ['+col.name+'] is not null'
from sys.tables tab
join sys.columns col
on tab.object_id = col.object_id
where col.name like 'name'

open cur_Select
fetch next from cur_Select into @q

while @@FETCH_STATUS = 0
begin
exec sp_executesql @q

fetch next from cur_Select into @q

end

close cur_Select
deallocate cur_Select

关于SQL - 查询以在数据库的所有表中查找特定列但没有空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30433360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com