如何向SQL Server中的现有表列添加注释?(复制)

时间:2021-10-18 16:45:45

Possible Duplicate:
SQL Comments on Create Table on SQL Server 2008

可能重复:SQL Server 2008上创建表的SQL注释

I just want to know how to add a comment to an existing table column in SQL Server? Seems simple, but I just don't find anything in the 5 first results that throw my search engine.

我只是想知道如何向SQL Server中的现有表列添加注释?看起来很简单,但是我在搜索引擎的第5个结果中找不到任何东西。

edits

编辑

Rather than using the UI, I would to know the SQL query.

我想知道SQL查询,而不是使用UI。

2 个解决方案

#1


23  

While creating the new table in the SQL Server Management Studio, Please refer to the below mentioned screen shot for adding the description to a column.

在SQL Server Management Studio中创建新表时,请参考下面提到的屏幕截图,以便将描述添加到列中。

如何向SQL Server中的现有表列添加注释?(复制)

Another way to do it programatically

另一种编程方式。

EXEC sp_updateextendedproperty 
@name = N'MS_Description', @value = 'Your description',
@level0type = N'Schema', @level0name = dbo, 
@level1type = N'Table',  @level1name = Your Table Name, 
@level2type = N'Column', @level2name = Yuur Column Name;

#2


7  

That depends on what you mean by "comment". If you want to add descriptive text to a column, you can set the Column Description using SQL Server Management Studio:

这取决于你所说的“评论”是什么意思。如果要向列添加描述性文本,可以使用SQL Server Management Studio设置列描述:

To set the description programmatically, you can use the sp_addextendedproperty, sp_updateextendedproperty and sp_dropextendedproperty stored procedures. Example:

要以编程方式设置描述,可以使用sp_addextendedproperty、sp_updateextendedproperty和sp_dropextendedproperty存储过程。例子:

EXEC sp_addextendedproperty 
    @name = N'MS_Description', @value = 'This is the description of my column',
    @level0type = N'Schema', @level0name = 'dbo',
    @level1type = N'Table', @level1name = 'MyTable', 
    @level2type = N'Column', @level2name = 'MyColumn'

I admit that the syntax is a bit inconvenient -- the following blog post contains stored procedures that make this process a bit easier:

我承认语法有点不方便——下面的博客文章包含一些存储过程,使这个过程更容易:

#1


23  

While creating the new table in the SQL Server Management Studio, Please refer to the below mentioned screen shot for adding the description to a column.

在SQL Server Management Studio中创建新表时,请参考下面提到的屏幕截图,以便将描述添加到列中。

如何向SQL Server中的现有表列添加注释?(复制)

Another way to do it programatically

另一种编程方式。

EXEC sp_updateextendedproperty 
@name = N'MS_Description', @value = 'Your description',
@level0type = N'Schema', @level0name = dbo, 
@level1type = N'Table',  @level1name = Your Table Name, 
@level2type = N'Column', @level2name = Yuur Column Name;

#2


7  

That depends on what you mean by "comment". If you want to add descriptive text to a column, you can set the Column Description using SQL Server Management Studio:

这取决于你所说的“评论”是什么意思。如果要向列添加描述性文本,可以使用SQL Server Management Studio设置列描述:

To set the description programmatically, you can use the sp_addextendedproperty, sp_updateextendedproperty and sp_dropextendedproperty stored procedures. Example:

要以编程方式设置描述,可以使用sp_addextendedproperty、sp_updateextendedproperty和sp_dropextendedproperty存储过程。例子:

EXEC sp_addextendedproperty 
    @name = N'MS_Description', @value = 'This is the description of my column',
    @level0type = N'Schema', @level0name = 'dbo',
    @level1type = N'Table', @level1name = 'MyTable', 
    @level2type = N'Column', @level2name = 'MyColumn'

I admit that the syntax is a bit inconvenient -- the following blog post contains stored procedures that make this process a bit easier:

我承认语法有点不方便——下面的博客文章包含一些存储过程,使这个过程更容易: