Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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)

Columns Explorer - With constraints create / drop scripts (no cursors)

By antonio cuna,

/******* columns explorer *******/
/* Goal: returns info about each column constraint and indexes
Scope: current database

Use: execute script

---------------- result set ----------------
schemaName (nvarchar): current table schema
tableName (sysname): current table name
columnName (sysname): current column name
dataType (sysname): current column data type
maxLegth (smallint): current column data max lenght
precision (tinyint): current column data precison
scale (tinyint): current column data scale
collationName (sysname): current column collation name
isIdenty (bit): if current column is an identity column
isNullable (bit): if current column allows Null values
isFkTable (bit): if current table has foreign keys
isFkColumn (bit): if current column is a foreign key column
isPkTable (bit): if current table has a primary key
isPkColumn (bit): if current column is a primary key column
colOrderInPK (tinyint): current column ordinal in the primary key definition
isIndexedColumn (bit): if current colum is indexed
indexName (sysname): index name to which the current column belongs
indexType (varchar): index type to which the current column belongs
isUniqueIndex (bit): if [indexName] is a unique index
isUniqueConstraint (bit): if [indexName] is a unique index
idxColOrder (tinyint): current column ordinal in the [indexName] definition
hasDefault (bit): if current column has a default constraint
hasTableCheck (bit): if there's a table check constraint
hasColumnCheck (bit): if current column table check constraint
foreignKeyName (sysname): foreign key to which current column belongs
fkColumns (nvarchar): all columns of the [foreignKeyName] constraint
pkTableName (nvarchar): table name whit the primary key to which [foreignKeyName] refers to
referencedPkColumns (nvarchar): column names of the the primary key to which [foreignKeyName] refers to
fkCreateStmt (nvarchar): statement to create [foreignKeyName]
fkDropStmt (nvarchar): statement to drop [foreignKeyName]
defaultName (sysname): default constraint name for the current column
defaultValue (nvarchar): default constraint value for the current column
defaultCreateStatement (nvarchar): statement to create default constraint [defaultName]
defaultDropStatement (nvarchar): statement to drop default constraint [defaultName]
checkName (sysname): check constraint name for the current column / table
checkDefinition (nvarchar): definition of check constraint [defaultName]
checkCreateStmt (nvarchar): statement to create check constraint [defaultName]
checkDropStmt (nvarchar): statement to drop check constraint [defaultName]

lindbergh_ddv@hotmail.com (2011)
*/

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

Identifying ASCII characters in NVARCHAR columns

Identifying ASCII characters in NVARCHAR columns

SCRIPT

Check Candidate Columns for NOT NULL Constraints

This script reports table columns that allow NULL values but that currently have no NULL values, mak...

FORUM

FK selection (an nvarchar(30) column or four int columns)

FK selection (an nvarchar(30) column or four int columns)

FORUM

constraints on columns while creating the table

constraints on columns while creating the table

FORUM

Unique Constraint for 2 columns in SQL 2005

Unique Constraint for 2 columns in SQL 2005

Tags
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones