plsql 建表 如何添加注释
plsql 在oracle中创建表时添加注释使用comment字段。例如有以下表:
CREATE TABLE t1(
id varchar2(32) primary key,
name VARCHAR2(32) ,
age VARCHAR2(32)
)
添加表注释的命令为:
COMMENT ON table t1 IS '个人信息';
添加字段注释命令为:
comment on column t1.id is 'id';
comment on column t1.name is '姓名';
comment on column t1.age is '年龄';
扩展资料
plsql中查看表注释和字段注释方法介绍
查看当前用户下所有表注释:select * from user_tab_comments
结果: user_tab_comments:table_name,table_type,comments
查看当前用户下某表所有字段注释:select * from user_col_comments where TABLE_NAME='某表名称';
结果:user_col_comments:table_name,column_name,comments
建表:
CREATE TABLE CORPREPORTERINFO(
CRID NUMBER NOT NULL,
CORPID VARCHAR2(8) NOT NULL,
CRNAME VARCHAR2(20),
PRIMARY KEY(CRID,CORPID)
)
TABLESPACE "AGR";
添加表注释:
COMMENT ON table CORPREPORTERINFO IS '上报员表';
添加字段注释:
comment on column CORPREPORTERINFO.CRID is 'id';
comment on column CORPREPORTERINFO.CORPID is '企业id';
comment on column CORPREPORTERINFO.CRNAME is '名称';
扩展资料:
注意事项
plsql创建表后不能直接让id递增,要手动创建。
例如:
SQL:
create table student(
id number primary key,
name varchar2(20)not null,
age int
);
SQL:
create trigger student_trig before
insert on student for each row when (new.id is null)
begin
select student_id_seq.nextval into:new.id from dual;
end;
因为plsql和mysql等其他数据库不相同,上面的三个步骤,一步都不能少,单单有表和序列还是不能实现,还要写一个触发器来执行它,才能真正成功,下面就可以插入数据了
SQL:
insert into student(name,age) values('jack',12);
CREATE TABLE CORPREPORTERINFO(
CRID NUMBER NOT NULL,
CORPID VARCHAR2(8) NOT NULL,
CRNAME VARCHAR2(20),
PRIMARY KEY(CRID,CORPID)
)
TABLESPACE "AGR";
添加表注释:
COMMENT ON table CORPREPORTERINFO IS '上报员表';
添加字段注释:
comment on column CORPREPORTERINFO.CRID is 'id';
comment on column CORPREPORTERINFO.CORPID is '企业id';
comment on column CORPREPORTERINFO.CRNAME is '名称';