/*獲取用戶表信息光標*/
SET NOCOUNT ON
DECLARE find_user_table CURSOR
FOR
SELECT [name]
WHERE type=
ORDER BY [name]
DECLARE @cName VARCHAR(
DECLARE @crdate DATETIME /*定義表創建日期變量*/
DECLARE @Rows INT /*定義表行數變量*/
CREATE TABLE #tmpTable /*創建用來儲存信息的臨時表*/
(
Tablename VARCHAR(
crDate datetime
Row INT
)
OPEN find_user_table /*打開游標*/
FETCH NEXT FROM find_user_table INTO @cName
WHILE @@FETCH_STATUS=
BEGIN
DECLARE @cSql nvarchar(
SELECT @par=
SELECT @cSql=
EXECUTE sp_executesql @cSql
INSERT INTO #tmpTable valueS(@cName
FETCH NEXT FROM find_user_table INTO @cName
END
SELECT * FROM #tmpTable /*顯示所有表信息*/
DROP TABLE #tmpTable /*刪除臨時表*/
CLOSE find_user_table /*關閉游標*/
DEALLOCATE find_user_table /*釋放游標*/
From:http://tw.wingwit.com/Article/program/SQLServer/201311/11238.html