SqlServer创建数据表描述及列描述信息
SqlServer创建数据表描述及列描述信息
Intro
Q: 为什么要创建描述信息?
A: ⿏标悬停在对应表和列上时,会出现描述信息,可以提⾼⼯作的效率,借助⼯具我们根据数据表可以⽣成Model,可以将描述信息。
添加描述语法
添加描述存储过程【sp_addextendedproperty】语法
sp_addextendedproperty
[ @name = ] { 'property_name' }
[ , [ @value = ] { 'value' }
[ , [ @level0type = ] { 'level0_object_type' }
, [ @level0name = ] { 'level0_object_name' }
[ , [ @level1type = ] { 'level1_object_type' }
, [ @level1name = ] { 'level1_object_name' }
[ , [ @level2type = ] { 'level2_object_type' }
, [ @level2name = ] { 'level2_object_name' }
]
]
]
]
[;]
2019个税退税流程参数说明
[ @name ] = { 'property_name' }
Is the name of the property to be added. property_name is sysname and cannot be NULL. Names can also include blank or non-alphanumeric character strings, and binary values.
[ @value= ] { 'value'}
Is the value to be associated with the property. value is sql_variant, with a default of NULL. The size of value cannot be more than 7,500 bytes.
[ @level0type= ] { 'level0_object_type' }
Is the type of level 0 object. level0_object_type is varchar(128), with a default of NULL.
教师节贺卡Valid inputs are ASSEMBLY, CONTRACT, EVENT NOTIFICATION, FILEGROUP, MESSAGE TYPE, PARTITION FUNCTION, PARTITION SCHEME, REMOTE SERVICE BINDING, ROUTE, SCHEMA, SERVICE, USER, TRIGG [ @level0name= ] { 'level0_object_name' }
Is the name of the level 0 object type specified. level0_object_name is sysname with a default of NULL.
[ @level1type= ] { 'level1_object_type' }
Is the type of level 1 object. level1_object_type is varchar(128), with a default of NULL. Valid inputs are AGGREGATE, DEFAULT, FUNCTION, LOGICAL FILE NAME, PROCEDURE, QUEUE, RULE, SYNONYM, TABLE, TABLE [ @level1name= ] { 'level1_object_name' }
Is the name of the level 1 object type specified. level1_object_name is sysname, with a default of NULL.
[ @level2type= ] { 'level2_object_type' }
Is the type of level 2 object. level2_object_type is varchar(128), with a default of NULL. Valid inputs are COLUMN, CONSTRAINT, EVENT NOTIFICATION, INDEX, PARAMETER, TRIGGER, and NULL.
[ @level2name= ] { 'level2_object_name' }
Is the name of the level 2 object type specified. level2_object_name is sysname, with a default of NULL.
[ @name = ] { 'property_name' }
要添加的属性名称。property_name 的数据类型为 sysname,它不能是 NULL。名称可能还包括空⽩或⾮字母数字字符串和⼆进制值。
[ @value = ] { 'value' }
将要与属性相关联的值。value 的数据类型为 sql_variant,带有默认设置 NULL。value 的⼤⼩不能超过 7,500 字节;否则 SQL Server 会产⽣错误。
[ @level0type = ] { 'level0_object_type' }
⽤户或⽤户定义类型。level0_object_type 的数据类型为 varchar(128),其默认值为 NULL。有效的输⼊是 ASSEMBLY, CONTRACT, EVENT NOTIFICATION, FILEGROUP, MESSAGE TYPE,
PARTITION FUNCTION, PARTITION SCHEME, REMOTE SERVICE BINDING, ROUTE, SCHEMA, SERVICE, USER, TRIGGER, TYPE, PLAN GUIDE 和 NULL
[ @level0name = ] { 'level0_object_name' }
指定的 0 级对象类型的名称。level0_object_name 的数据类型为 sysname,其默认值为 NULL。
[ @level1type = ] { 'level1_object_type' }
1 级对象的类型。level1_object_type 的数据类型为 varchar(128),其默认值为 NULL。有效的输⼊是 AGGREGATE, DEFAULT, FUNCTION, LOGICAL FILE NAME, PROCEDURE, QUEUE, RULE,
SYNONYM, TABLE, TABLE_TYPE, TYPE, VIEW, XML SCHEMA COLLECTION 和 NULL。
[ @level1name = ] { 'level1_object_name' }
指定的 1 级对象类型的名称。level1_object_name 的数据类型为 sysname,其默认值为 NULL。
[ @level2type = ] { 'level2_object_type' }
2 级对象的类型。level2_object_type 的数据类型为 varchar(128),其默认值为 NULL。有效的输⼊是 COLUMN, CONSTRAINT, EVENT NOTIFICATION, INDEX, PARAMETER, TRIGGER 和 NULL。
[ @level2name = ] { 'level2_object_name' }
指定的 2 级对象类型的名称。level2_object_name 的数据类型为 sysname,其默认值为 NULL。
返回值为0则成功,1则失败
更新描述
sp_updateextendedproperty
[ @name = ]{ 'property_name' }
[ , [ @value = ]{ 'value' }
[, [ @level0type = ]{ 'level0_object_type' }
, [ @level0name = ]{ 'level0_object_name' }
[, [ @level1type = ]{ 'level1_object_type' }
, [ @level1name = ]{ 'level1_object_name' }
[, [ @level2type = ]{ 'level2_object_type' }
, [ @level2name = ]{ 'level2_object_name' }
]
]
]
]
更新描述和添加的语法差不多,在此就不再赘述
USER 还是 SCHEMA
msdn 给出的⽂档⾥这么说:
The ability to specify USER as a level 0 type in an extended property of a level 1 type object will be removed in a future version of SQL Server. Use SCHEMA as the level 0 type instead. For
example, when defining an extended property on a table, specify the schema of the table instead of a user name. The ability to specify TYPE as level-0 type will be removed in a future version of
SQL Server. For TYPE, use SCHEMA as the level 0 type and TYPE as the level 1 type.
在级别1类型对象的扩展属性中将USER指定为级别0类型的功能将在未来版本的SQL Server中删除。使⽤SCHEMA作为0级类型。例如,在表上定义扩展属性时,请指定表的模式,⽽不是⽤户名。将
在未来版本的SQL Server中删除将TYPE指定为级别0类型的能⼒。对于TYPE,使⽤SCHEMA作为0级类型,使⽤TYPE作为1级类型。
We do not recommend specifying USER as a level 0 type when you apply an extended property to a database object, because this can cause name resolution ambiguity. For example, assume
user Mary owns two schemas (Mary and MySchema) and these schemas both contain a table named MyTable. If Mary adds an extended property to table MyTable and specifies @level0type =
N'USER', @level0name = Mary, it is not clear to which table the extended property is applied. To maintain backward compatibility, SQL Server will apply the property to the table that is contained in
the schema named Mary.
当将扩展属性应⽤于数据库对象时,我们不建议将USER指定为级别0类型,因为这可能会导致名称解析模糊。例如,假设⽤户Mary拥有两个模式(Mary和MySchema),这些模式都包含⼀个名为晋怎么读
MyTable的表。如果Mary向表MyTable添加扩展属性并指定@ level0type = N'USER',@ level0name = Mary,则不清楚扩展属性应⽤于哪个表。为了保持向后兼容性,SQL Server会将该属性应⽤于苹果手机充电充不进去什么原因
包含在名为Mary的模式中的表。
就业前景最好专业总结来说,当将扩展属性应⽤于数据库对象时,微软推荐使⽤ SCHEMA,不推荐 USER,但是 USER 还是会保留,还是可以使⽤但是在某些情况下(如上所述)可能会出现⾃⼰意料之外的事情。
⽰例
1 -- 查询
2 SELECT [TypeId] , [TypeName]
3 FROM [dbo].[tabBlockType];
4
5 -- USER (不推荐)
6 -- 添加表 tabBlockType 描述
7 EXECUTE sp_addextendedproperty N'MS_Description', N'⿊名单类型表', N'USER', N'dbo',
8 N'table', N'tabBlockType';
9
10 -- 添加列 TypeId 描述
11 EXECUTE sp_addextendedproperty N'MS_Description', N'⿊名单类型id', N'USER', N'dbo',
12 N'TABLE', N'tabBlockType', N'COLUMN', N'TypeId';
13 -- 添加列 TypeName 描述
14 EXECUTE sp_addextendedproperty N'MS_Description', N'⿊名单类型名称', N'USER', N'dbo',
15 N'TABLE', N'tabBlockType', N'COLUMN', N'TypeName';
16
17 -- 更新列 TypeName 描述
18 EXECUTE sp_updateextendedproperty N'MS_Description', N'⿊名单类型', N'USER', N'dbo',
19 N'TABLE', N'tabBlockType', N'COLUMN', N'TypeName';
20
21 -- SCHEMA (推荐)
22 -- 添加表 tabBlockType 描述
23 EXECUTE sp_addextendedproperty N'MS_Description', N'⿊名单类型表', N'SCHEMA', N'dbo',
24 N'table', N'tabBlockType';
农业银行帐号25
26 -- 添加列 TypeId 描述
27 EXECUTE sp_addextendedproperty N'MS_Description', N'⿊名单类型id', N'SCHEMA', N'dbo',
28 N'TABLE', N'tabBlockType', N'COLUMN', N'TypeId';
29 -- 添加列 TypeName 描述
30 EXECUTE sp_addextendedproperty N'MS_Description', N'⿊名单类型名称', N'SCHEMA', N'dbo',
31 N'TABLE', N'tabBlockType', N'COLUMN', N'TypeName';
32
33 -- 更新列 TypeName 描述
34 EXECUTE sp_updateextendedproperty N'MS_Description', N'⿊名单类型', N'SCHEMA', N'dbo',
35 N'TABLE', N'tabBlockType', N'COLUMN', N'TypeName';
36
37 -- 创建 Create sql 脚本⽣成的添加描述脚本
38
39 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'⿊名单类型id' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tabBlockType', @level2type
40 GO
41
42 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'⿊名单类型' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tabBlockType', @level2type
43 GO
44
45 EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'⿊名单类型表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tabBlockType'
46 GO
sql 总览
创建create 语句时描述信息也会导出
More
参考资料
(注:这篇博客中有⼏点错误的地⽅,推荐看上⾯两篇,官⽅⽂档最准)
In the end
笔者⽔平有限,如果发现有什么错误的地⽅,欢迎指出,欢迎与我联系
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论