概述:
原先一直用Mysql,記得最后接觸SQL Server還是大學的數據庫原理課。
在項目中遇到的問題:對數據庫中的表和字段進行注釋好便於團隊協作。
要點:
需求:
在創建數據庫是對相應的數據庫、表、字段給出注釋。
解決方案:
首先,要明確一點的是注釋存在sysproperties表中而不是跟創建的表捆綁到一起的(我的理解)。
一、使用SQL Server窗口創建表是會有注釋窗口;
二、使用SQL語句的comment語句,該語句放置在create table()后面,如:
comment on table table_name is 'table_mark'
comment on column table_name."Column" is 'column_mark'
三、調用系統存儲過程sp_addextendedproperty來添加注釋,如:
EXECUTE sp_addextendedproperty N'MS_Description',N'雇員信息',N'user',N'dbo',N'table',N'Employee',NULL,NULL
EXECUTE sp_addextendedproperty N'MS_Description',N'主鍵ID,自動增加',N'user',N'dbo',N'table',N'Employee',N'column',N'EmployeeID'
或者
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'角色ID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CharData', @level2type=N'COLUMN',@level2name=N'charid'
GO
小結:
學習中的點滴記錄...