orcale 常用DDL 语句

来源:互联网 发布:电子海报制作软件 编辑:程序博客网 时间:2024/05/18 00:10
--查看用户表

select * from  user_tables;

--查看表中列信息

select * from user_tab_columns where table_name='product';

--修改表
--1 增加列
alter table rui_test add age int;
alter table rui_test add birthday date default sysdate not null;

--2 增加虚拟列
alter table rui_test add (ave_num as (low+high)/2);

--3 修改列的长度


--4 修改数字列的精度
alter table rui_test modify id number(5);

--5 修改列的数据类型
 alter table rui_test modify status char(15);

--6 修改列的默认值
alter table rui_test modify status default -1;

--7 删除列
 alter table rui_test drop column status;

--8 添加CHECK约束
 alter table rui_test add constraint order_staus_ck check (status in('A','B','C'));

--9 NOT NULL约束
 alter table rui_test modify status constraint order_status_nn not null;

--10 FOREIGH KEY 约束
 alter table rui_test add constraint order_status_fk references employees(employee_id);

--11 UNIQUE 约束
alter table rui_test add constraint order_status_uq unique (stauts);

--12 删除约束
alter table rui_test drop constraint order_status_uq;

--13 禁用约束
alter table rui_test disable constraint order_status_nn;

--14 启用约束
alter table rui_test enable constraint order_status_nn;

-- 15 重命名表
rename rui_ole to rui_new;

--16 向表中添加注释
comment on table rui_test status is '状态';

--17 截断表
truncate table rui_test;

0 0
原创粉丝点击