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