欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

常用sql查询语句

程序员文章站 2022-04-20 14:48:34
...
查询数据库所有表
select table_name from information_schema.tables 


查询数据库所有字段
select table_name from information_schema.columns 



查询数据库所有视图
select table_name from information_schema.views



查询数据库所有表数据
DECLARE TableCursor SCROLL CURSOR FOR
select table_name from information_schema.columns order by table_name
OPEN TableCursor

DECLARE @TmpTableName Nvarchar(100);

WHILE 1 = 1
BEGIN
FETCH NEXT FROM TableCursor INTO @TmpTableName
If @@FETCH_STATUS != 0
BEGIN
break
End
ELSE
--print @TmpTableName
BEGIN TRY
exec('select * from ' + @TmpTableName );
END TRY
BEGIN CATCH
exec('select * from ' + @TmpTableName);
END CATCH
END

CLOSE TableCursor
DEALLOCATE TableCursor
相关标签: SQL Server