SQL Server-可以在CREATE TABLE中添加字段描述吗? [英] SQL Server - Can you add field descriptions in CREATE TABLE?

查看:68
本文介绍了SQL Server-可以在CREATE TABLE中添加字段描述吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以看到很多关于字段描述扩展属性的住处以及如何获得它的帖子,但是在CREATE TABLE阶段添加这些内容一无所获。

I can see plenty of posts about where the field description extended property lives and how I can get it, but nothing about adding these at the CREATE TABLE stage.

我正在动态创建表,因此动态添加字段描述将是一件很整洁的事情,但我看不到一种方法。

I'm dynamically creating tables so dynamically adding field descriptions would be a tidy thing to do but I cannot see a way.

有人能做到吗?

推荐答案

虽然在 CREATE TABLE 中无法做到,但是可以做到同时在同一数据库脚本中,使用此方法

While you can't do it in CREATE TABLE, you can do it at the same time, in the same database script, using this approach:

CREATE table T1 (id int , name char (20))

EXEC   sp_addextendedproperty 'MS_Description', 'Employee ID', 'user', dbo, 'table', 'T1', 'column', id

EXEC   sp_addextendedproperty 'MS_Description', 'Employee Name', 'user', dbo, 'table', 'T1', 'column', name

然后能够使用以下命令查看您的条目:

Then you can see your entries using this:

SELECT   *
FROM   ::fn_listextendedproperty (NULL, 'user', 'dbo', 'table', 'T1', 'column', default)

这篇关于SQL Server-可以在CREATE TABLE中添加字段描述吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆