创建表:
create table cqytest(
id number(1),
username varchar2(11),
password varchar2(11)--最后一个字段后面必须没有逗号
)tablespace cqyspace;
复制表:
create table test1 as select * from cqy.cqytest; --复制cqy用户的cqytest表
删除表:
drop table test1 cascade constraints;
给表添加注释:
comment on table cqytest is '我的测试表';
给字段添加注释:
comment on column cqyt1.id is '主键';
修改字段名:
alter table cqytest rename column id to userid;
添加字段:
alter table cqytest add email varchar2(11);
删除字段:
alter table cqytest drop column email;
修改字段类型:
alter table cqytest modify email varchar2(20);
查询所有约束:
select constraint_name from user_cons_columns;
建表时添加默认值、主键、外键,非空约束
create table cqyt1(
id number(11) not null primary key,--非空,主键,唯一(unique),foreign key id references cqytable
groupid number(11) check(groupid>22 and groupid<33),--条件约束
username varchar2(20),
password varchar2(20)
)tablespace cqyspace;