標籤:style http color strong 資料 io 2014 for
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);