Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding a column description

Does anyone know how to add a description to a SQL Server column by running a script? I know you can add a description when you create the column using SQL Server Management Studio.

How can I script this so when my SQL scripts create the column, a description for the column is also added?

like image 662
EJC Avatar asked Sep 20 '10 18:09

EJC


People also ask

How do you write a Description in SQL?

Since in database we have tables, that's why we use DESCRIBE or DESC(both are same) command to describe the structure of a table. Syntax: DESCRIBE one; OR DESC one; Note : We can use either DESCRIBE or DESC(both are Case Insensitive).

How do you add a column to a table?

Add a column to the left or right Under Table Tools, on the Layout tab, do one of the following: To add a column to the left of the cell, click Insert Left in the Rows and Columns group. To add a column to the right of the cell, click Insert Right in the Rows and Columns group.


2 Answers

I'd say you will probably want to do it using the sp_addextendedproperty stored proc.

Microsoft has some good documentation on it.

Try this:

EXEC sp_addextendedproperty      @name = N'MS_Description', @value = 'Hey, here is my description!',     @level0type = N'Schema',   @level0name = 'yourschema',     @level1type = N'Table',    @level1name = 'YourTable',     @level2type = N'Column',   @level2name = 'yourColumn'; GO 
like image 170
Abe Miessler Avatar answered Oct 08 '22 22:10

Abe Miessler


This works for me. Relevant arguments are indicated with little arrows.

EXEC sys.sp_addextendedproperty    @name=N'MS_Description'  ,@value=N'Here is my description!'  --<<<<  ,@level0type=N'SCHEMA'  ,@level0name=N'dbo'  ,@level1type=N'TABLE'  ,@level1name=N'TABLE_NAME' --<<<<  ,@level2type=N'COLUMN'  ,@level2name=N'FIELD_NAME'  --<<<< 
like image 23
JosephStyons Avatar answered Oct 08 '22 23:10

JosephStyons