Add A Column To A Table With ExtendedProperty

Share your SQL code snippets for SQL Prompt!

Moderators: David Atkinson, Anu Deshpande, Luke Jefferson, Paul Stephenson

Add A Column To A Table With ExtendedProperty

Postby aultmike » Tue Jul 13, 2010 9:41 pm

I use this snippet when I want to add a column to a table and want to add a blurb about this columns purpose.

Getting into the habit of using the ExtendedProperty also allows me to use SQLDoc to create documentation. No brainer! ;-)

USE <DatabaseName>

BEGIN TRANSACTION
GO
ALTER TABLE dbo.<TableName> ADD <ColumnName> <DataType> NULL
GO
--The statement below allows you to add a description to the field
--you're adding so that you can use SQLDoc to generate documentation
EXEC sp_addextendedproperty N'MS_Description',
N'<Description of the purpose of the column>',
'SCHEMA', N'dbo', 'TABLE', N'<TableName>', 'COLUMN', '<ColumnName>'
GO
COMMIT
GO
aultmike
 
Posts: 26
Joined: Fri Jan 08, 2010 3:49 pm
Location: Canton, OH

Return to SQL Prompt code snippets

Who is online

Users browsing this forum: No registered users and 0 guests