Generating Descriptions for All Tables in a Database
A reader offers a tip for modifying a stored procedure so that it returns a description of all user-defined tables in a database.
November 19, 2001
I enjoyed Joe Bishop's tip "Generating a Table Description" (November 2000). Bishop provided examples of code he uses to quickly reference SQL Server 6.5 table structures such as column names, data types, field lengths, and null status of fields. Listing 4 shows how I used a T-SQL cursor to modify Bishop's stored procedure so that the procedure returns a description of all user-defined tables in a particular database. The expression type = 'U' returns entries that refer to user-defined tables. The expression type = 'S' returns entries that refer to system tables. The combination of both expressions returns entries that refer to all tables in the database. Listing 4 shows that I've expanded the WHERE clause by adding the expression OR type = 'S'. If you encounter isolated situations for which you want to return only information about user-defined tables, you can insert a double-hyphen (—), which signals a comment line, in front of the type = 'S' instruction.
—Jörg Böhmichen
[email protected]
About the Author
You May Also Like