Generating Descriptions for All Tables in a Database


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.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.