Oracle、Mysql、SqlServer創建表和給表和字段加注釋 一、Oracle --創建表 create table test ( id varchar2(200) primary key not null, sort number, name varchar(200) ) --字段加注釋 comment on column test.id is 'id'; comment on column test.sort is '序號'; --表加注釋 comment on table test is '測試表' -------------------------------------------------------------------------------------- 二.Mysql --創建表 create table test ( id varchar(200) not null, sort int(11) comment '排序', name varchar(200) comment '名稱', ) --表加注釋 alter table test comment ='測試表' --------------------------------------------------------------------------------------- 三.SqlServer --創建表 create table test ( id varchar(200) primary key not null, sort int, name varchar(200), ) --給字段加注釋 EXEC sp_addextendedproperty N'test', N'序號', N'user', N'dbo', N'table', N'test', N'column', N'sort'; --表加注釋 EXECUTE sp_addextendedproperty N'test', N'測試表', N'user', N'dbo',N'table', N'test', NULL, NULL 刪除字段注釋 execute sp_dropextendedproperty 'MS_Description','user','dbo','table','testTable','column','testRecord'; 刪除表注釋 execute sp_dropextendedproperty 'MS_Description','user','dbo','table','testTable',null,null; --------------------------------- sqlserver --表加注釋 EXECUTE sp_addextendedproperty N'MS_Description', N'賬號類型表', N'user', N'dbo',N'table', N'Account_Type', NULL, NULL --獲取表注釋 SELECT isnull(B.name,'')as name,A.value FROM sys.extended_properties A LEFT JOIN sys.columns B ON A.major_id=B.object_id AND A.minor_id=B.column_id LEFT JOIN sys.tables C ON A.major_id=C.object_id WHERE A.class=1 AND C.name='Account_Type' and isnull(B.name,'')='' --給字段加注釋 EXEC sp_addextendedproperty N'MS_Description', N'序號', N'user', N'dbo', N'table', N'Account_Type', N'column', N'Type_Id'; --獲取字段注釋 SELECT A.value FROM sys.extended_properties A LEFT JOIN sys.columns B ON A.major_id=B.object_id AND A.minor_id=B.column_id LEFT JOIN sys.tables C ON A.major_id=C.object_id WHERE A.class=1 AND B.name='Type_Id' AND C.name='Account_Type'