-- 取得資料庫中的資料表,並建立儲存到 #LISTTABLES 這資料表中 select distinct 表格名稱 into#LISTTABLES from ( SELECT Top 100PERCENT a.TABLE_NAME as 表格名稱 FROM INFORMATION_SCHEMA.TABLES a LEFTJOIN INFORMATION_SCHEMA.COLUMNS b ON ( a.TABLE_NAME=b.TABLE_NAME ) WHERE a.TABLE_TYPE='BASE TABLE' and a.TABLE_NAME != 'sysdiagrams' ORDERBY a.TABLE_NAME, ordinal_position) c;
declare @tablename nvarchar(max)
declare icur cursorstaticforselect * from#LISTTABLES OPEN icur
fetchnextfrom icur into @tablename while(@@FETCH_STATUS=0) BEGIN