Oracle、Mysql、SqlServer创建表和给表和字段加注释

前端之家收集整理的这篇文章主要介绍了Oracle、Mysql、SqlServer创建表和给表和字段加注释前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Oracle、MysqLsqlServer创建表和给表和字段加注释 
一、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 Ntest,N序号,Nuser,Ndbo,Ntable,Ntest,Ncolumn,Nsort;
--表加注释
EXECUTE sp_addextendedproperty Ntest,N测试表,NULL,NULL 
删除字段注释  
execute sp_dropextendedproperty MS_Description,user,dbo,table,testTable,column,testRecord;  
删除表注释  
execute sp_dropextendedproperty MS_Description,null,null;   

---------------------------------

sqlserver

--表加注释
EXECUTE sp_addextendedproperty NMS_Description,N账号类型表,NAccount_Type,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 NMS_Description,NType_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

猜你在找的Oracle相关文章