SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Retrieve column attributes

By anonuser,

Given database, owner, table, and column names, this procedure returns one from among several column attributes such as type definition, defaults, and other types of constraints.  E.g., to retrieve the type definition of the 'pubs' database's 'author.address':

DECLARE @attrib VARCHAR (500)
      , @msg    VARCHAR (8000)

EXEC p_get_column_attribute 'TYPEDEF'
                          , 'authors'
                          , 'address'
                          , @msg    OUTPUT
                          , @attrib OUTPUT
                          , 'pubs', 'dbo'
PRINT @attrib

(Answer:  'VARCHAR (40)')

Total article views: 110 | Views in the last 30 days: 1
Related Articles

Updating varchar(max) column

Updating varchar(max) column


Aggregrating varchar columns

Concatenate columns grouping on Index column (approach for summing varchar columns by grouping on in...


Altering column from varchar(2048) to varchar(max) performance

Altering column datatype to varchar(max)


Varchar column conversion

Converting a column with Data Type of Varchar to Datetime


Export VarChar(6500) column

Unable to export VarChar(6500) column to CSV / XLS