-- SQL reads all fields in a specified data table
Declare @ tablename nvarchar (250) -- Name of the data table in the current operation
Set @ tablename = 'hzfa '-- specify the name of the data table to be queried (please change it to the name of the table in your own database)
Declare @ columnname nvarchar (250) -- Name of the field currently queried in the cursor
Declare @ columndescription nvarchar (250) -- Description of the fields currently queried in the cursor
-- Declare the cursor for reading all fields in the data table
Declare mycursor cursor for select. name, cast (G. value as nvarchar) from sys. columns A left join sys. extended_properties g on (. object_id = G. major_id and. column_id = G. minor_id) Where object_id = object_id (''+ @ tablename +'') order by object_id,. column_id
-- Open the cursor
Open mycursor
-- Retrieve the data from the cursor and assign values to the constraint name variable.
Fetch next from mycursor into @ columnname, @ columndescription
-- If the cursor is successfully executed
While (@ fetch_status = 0)
Begin
If (@ columndescription is null)
Begin
Print 'the description of the current data table ['+ @ tablename +'] field ['+ @ columnname +'] is blank'
End
Else
Begin
-- Query the field description currently found
The description of the print 'current data table ['+ @ tablename +'] field ['+ @ columnname +'] is ['+ @ columndescription +'] '.
End
-- Use a cursor to retrieve the next record
Fetch next from mycursor into @ columnname, @ columndescription
End
-- Close the cursor
Close mycursor
-- Undo cursor
Deallocate mycursor