-- Original design intention: Convert the data table of the simplified version to the traditional version
-- Query all user data tables with a cursor
Declare @ currenttablename nvarchar (250)
Declare usertablecursor cursor for -- declare a cursor
Select name from sysobjects where xtype = 'U' and Category = '000000' order by name
Open usertablecursor -- open the cursor
Fetch next from usertablecursor -- get the next row of the cursor
-- Make the variable get the name of the row specified by the current cursor
Into @ currenttablename
While @ fetch_status = 0 -- the fetch statement is successfully executed.
Begin
-- Query all constraints in the current data table
Print n 'current data table name' + @ currenttablename
-- Use a cursor to query constraints in a specified user data table
Declare @ constrainttype nvarchar (250)
Declare @ constraintname nvarchar (250)
Declare @ constraintvalue nvarchar (250)
Declare constraintcursor cursor for select. xtype as constraint type,. name as constraint name, isnull (B. text, N 'null') as default value from sysobjects a left Outer Join syscomments B on. id = B. ID where (objectproperty (. ID, N 'ismsshipped ') = 0) and. parent_obj = (select ID from sysobjects where name = @ currenttablename)
Open constraintcursor -- open the cursor
Fetch next from constraintcursor -- get the next row of the cursor
-- Make the variable get the name of the row specified by the current cursor
Into @ constrainttype, @ constraintname, @ constraintvalue
While @ fetch_status = 0 -- the fetch statement is successfully executed.
Begin
-- Query all constraints in the current data table
Print n 'current data table name' + @ currenttablename + N' constraint type '+ @ constrainttype + N' constraint name' + @ constraintname + N' default value' + @ constraintvalue
Fetch next from constraintcursor -- get the next row of the cursor
-- Obtain the name, cyclebegintime, and cycleendtime of the row specified by the current cursor.
Into @ constrainttype, @ constraintname, @ constraintvalue
End
Close constraintcursor -- close the cursor
Deallocate constraintcursor -- release cursor
Fetch next from usertablecursor -- get the next row of the cursor
-- Obtain the name, cyclebegintime, and cycleendtime of the row specified by the current cursor.
Into @ currenttablename
End
Close usertablecursor -- close the cursor
Deallocate usertablecursor -- release cursor