常用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