20140523 Oracle筆記

來源:互聯網
上載者:User

標籤: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);

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.