简体   繁体   中英

How to describe a column in a table - SQL Server

I just created a table

create table TestSchema.TestConfiguration
(
    SomeId int not null,
    LegacyColumnName bit default 0
);

Now I am trying to describe the table in the following way:

  exec sys.sp_addextendedproperty 
        @name = N'MS_Description ', 
        @value = N'My Organisation's Configuration table', 
        @level0type = N'SCHEMA',
        @level0name = N'TestSchema', 
        @level1type = N'TABLE',
        @level1name = N'TestConfiguration',
        @level2type = N'COLUMN',
        @level2name = N'LegacyColumnName';

I want to describe here in plain words what LegacyColumnName column stands for, something like @level2description ..

How do I do that ? Any ideas ?

If you execute the query as shown in your question

 exec sys.sp_addextendedproperty 
        @name = N'MS_Description ', 
        @value = N'My Organisation's Configuration table', 
        @level0type = N'SCHEMA',
        @level0name = N'TestSchema', 
        @level1type = N'TABLE',
        @level1name = N'TestConfiguration',
        @level2type = N'COLUMN',
        @level2name = N'LegacyColumnName';

then, My Organisation's Configuration table will become the description of the LegacyColumnName column.

In addition to @Raj's excellent answer, something below extends that answer:

Question: So, if I understand correctly, then the descriptions for the TestSchema, TestConfiguration, LegacyColumnName are all same ?

Answer: No

The following code just describes the purpose of 'Legacy Column Name'.

exec sys.sp_addextendedproperty 
        @name = N'MS_Description ', 
        @value = N'Legacy Column is used for blah blah blah', 
        @level0type = N'SCHEMA',
        @level0name = N'TestSchema', 
        @level1type = N'TABLE',
        @level1name = N'TestConfiguration',
        @level2type = N'COLUMN',
        @level2name = N'LegacyColumnName'; 

If you want to describe the table, then the following would do so.

exec sys.sp_addextendedproperty 
        @name = N'MS_Description ', 
        @value = N'My Organisation's Configuration table', 
        @level0type = N'SCHEMA',
        @level0name = N'TestSchema', 
        @level1type = N'TABLE',
        @level1name = N'TestConfiguration';

If you want to describe each and every column (or table, etc.,) you need to have explicit calls to sys.sp_addextendedproperty .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM