建立mssql的欄位描述的方法

  • 6568
  • 0
  • sql
  • 2013-11-07

摘要:建立mssql的欄位描述的方法

alter table table add codebsi nvarchar(10),spec nvarchar(100)

這是新增欄位,再來才建立欄位描述

 exec sp_addextendedproperty N'MS_Description', N'屬性', N'user', N'dbo', N'table', N'material', N'column', N'codebsi'
 exec sp_addextendedproperty N'MS_Description', N'規格', N'user', N'dbo', N'table', N'material', N'column', N'spec'
 

因為最近要把postgre的db轉移來ms sql,所以會常碰觸到db的東西,再此做個備忘,如果有前輩有更方便或正確的做法,再指點一下。

 

建立table語法範例



CREATE TABLE [dbo].[latest_news](
	[id] [int] NOT NULL identity(1,1),
	[title] [nvarchar](100) NULL,
	[content] [nvarchar](400) NULL,
PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

	

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'標題' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'latest_news', @level2type=N'COLUMN',@level2name=N'title'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'內容' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'latest_news', @level2type=N'COLUMN',@level2name=N'content'
GO

create index latest_news1 on latest_news(title)