Selasa, 20 Mei 2014

How To describe table structure in SQL Server

This post is about sp_columns which is used to describe the table structure of a SQL Server table.
The simplest way to use sp_columns to show the columns and related information about a SQL Server table is to execute the stored proecedure passing it the table name like so:

exec sp_columns MyTable

This returns a row for each column in the table, describing the column in detail.

The sp_columns stored procedure can take additional arguments to the table name. You can also pass the table owner, table qualifier (i.e. the database name), column name and the ODBC version used. The table owner and column name parameters support wildcard pattern matching, so you can use % and _

For example, if you only wanted to query the "foo" column from the above example, you would do this:

exec sp_columns MyTable, @column_name = 'foo'

If you wanted to query all columns which started with the letter "a" you could do the following:

exec sp_columns MyTable, @column_name = 'a%'
How To describe table structure in SQL Server


Source:http://www.tutorialsdesk.com/2012/09/how-to-describe-table-structure-in-sql.html

Tidak ada komentar:

Posting Komentar