SQL Server——建表时为字段添加注释

在 MySQL 中,新建数据库表为字段添加注释可以使用 comment 属性来实现。SQL Server 没有 comment 属性,但是可以通过执行 sys.sp_addextendedproperty 这个存储过程添加扩展属性来实现相同的功能。

这个存储过程的参数定义如下:

sql 复制代码
exec sys.sp_addextendedproperty
    @name, @value,
    @level0type, @level0name,
    @level1type, @level1name,
    @level2type, @level2name
go

固定的参数如下:

sql 复制代码
exec sys.sp_addextendedproperty
    'MS_Description', @value,
    'SCHEMA', @level0name,
    'TABLE', @level1name,
    'COLUMN', @level2name
go
  • @value:要备注的内容。
  • @level0name:建表时指定的架构名。如果没有指定架构,填:dbo。
  • @level1name:表名。
  • @level2name:列名。

示例:

sql 复制代码
create table student
(
    id   bigint       not null primary key,
    name nvarchar(255),
)

exec sp_addextendedproperty 
	'MS_Description', N'名称', 
	'SCHEMA', 'dbo', 
	'TABLE', 'student', 
	'COLUMN', 'name'
go

select *
from student

DataGrip 显示效果为:

相关推荐
csdn_aspnet3 天前
如何在 MacOS 上安装 SQL Server
macos·sqlserver
简单的话*5 天前
如何查看SQL Server的当前端口
数据库·sqlserver
杰哥技术分享7 天前
Centos-mssql-server安装
linux·sqlserver·centos
一勺-_-9 天前
全栈:JDBC驱动版本和SQLserver版本是否有关系?怎么选择JDBC的版本号?
数据库·sqlserver
水根LP499 天前
利用微软SQL Server数据库管理员(SA)口令为空的攻击活动猖獗
数据库·microsoft·sqlserver·dba
iknow18111 天前
【Web安全】Sql注入之SqlServer和MySQL的区别
sql·mysql·sqlserver
安卓开发者15 天前
Android JUnit 测试框架详解:从基础到高级实践
android·junit·sqlserver
我来整一篇18 天前
[mssql] 分析SQL Server中执行效率较低的SQL语句
数据库·sql·sqlserver
不太厉害的程序员24 天前
Excel 将数据导入到SQLServer数据库
数据库·sqlserver·excel
-曾牛1 个月前
在Windows Server 2012 R2中安装与配置IIS服务并部署mssql靶机教程
运维·服务器·windows·网络安全·sqlserver·渗透测试·渗透测试靶机