首页 > 代码库 > 20140523 Oracle笔记
20140523 Oracle笔记
Oracle练习:
创建表格:
create table customer_info(id int primary key not null,first_name varchar(20),last_name varchar(20),sex char(2),age char(3));
创建序列:参考资料 http://zhidao.baidu.com/question/82436743.html
create sequence id_seq minvalue 1 maxvalue 10000000000000000 start with 1 increment by 1 cache 20 cycle;
修改表列名:
alter table table_name rename column column_name to xxx;
表中新增列:
alter table customer_info add(telephone varchar(30));
建立表的外键关系:
alter table purchase_item add foreign key(purchaser_id) references purchase_people(purchaser_id);
修改表名:
alter table table_nameA rename to table_nameB;
修改列数据类型:
alter table PURCHASE_ITEM modify STATUS_ID varchar2(20);
从表中删除列:
alter table tablename drop columname;
alter table purchase_item modify purchaser_id number(10);
oracle中往timestamp类型的列添加系统时间值:
insert into table(a)
values to_char(sysdate,‘yyyy-mm-dd hh24-mi-ss‘)
查询外键:
SELECT * FROM user_constraints;
多列定义为一个主键:
alter table purchase_item_detail ADD CONSTRAINT pk_purchase_item_detail PRIMARY KEY(purchase_item_detail_id,purchase_item_id);
给单独表格授权:
grant DELETE, INSERT, REFERENCES, SELECT, UPDATE on user_constraints to lisu;
约束所在的表有:
select * from user_constraints where table_name in (‘STOCK_IN_ITEM‘,‘STOCK_IN_ITEM_DETAIL‘);
delete from all_constraints where constraint_name in (‘SYS_C0011883‘,‘SYS_C0011886‘);
select * from dba_constraints;
select * from all_constraints where owner =‘LISU‘;
date类型插入值:
insert into user_login (user_login_id,operate_date) values (‘admin‘,sysdate);