oracle資料庫小總結

來源:互聯網
上載者:User

標籤:upd   外鍵   不能   ons   date   div   table   size   logs   

---資料庫小總結---1.資料庫的基本常用資料類型

①varchar2(size)              //浮動長度字元類型:長度會改變,根據使用者輸入的值進行相應的長度改變,節省記憶體空間

②char(size)                //固定字元長度,如果使用者輸入的值得長度,不夠size,則系統預設用空格代替

③number(1,2)              //數字類型,包含小數和整數(1.代表數位總長度/位元  2.表示小數點後的長度/位元)

④date              //時間類型  sysdate(系統時間) to_date(‘輸入的時間‘,‘時間的格式’)  時間格式一般YYYY-MM-DD

 

2.DDL 資料定義語言 (Data Definition Language)

2.1建立表

create table test1(   test2 varchar2(20) primary key,              //primary key  主鍵(一個表只能有一個,且不能重複和為空白)   test3 number(5,2) not null,                  //not null  不可為空   null可以為空白(預設約束為null)   test4 char(10) not null,                        test5 date default(sysdate)                  //default 添加預設約束);

 

2.2 進行對錶的增加,修改,刪除

alter table test1 add(test2 varchar2(20) not null);       //其中test1為表名 test2為增加的列名,not null為約束alter table test1 modify(test2 vatchar2(20) not null);    //其中varchar2(20) 為修改後的屬性 not null 約束根據以前寫沒寫適當添加alter table test1 drop(test2);                            // test2 為test1中刪除的列名drop table test1                         // 直接刪除表test1  

 

2.3 添加約束

alter table test add constraint fk_test1 foreign key(test1) refenerces test3(test1)  //添加外鍵約束,test3表中的test1列為其主鍵,test1為test表中的要添加的外鍵alter table test add constraint ck_test1 check(條件)                                  //添加檢查約束,賦值時的約束條件alter table test add constraint un_test1 unique(test1)                               //唯一約束,不能重複,可以有一個為空白的值

 

3.DML語言 資料操作語言

insert into test1(test2,3,4) values(2,3,4)         //給表進行賦值,test1為表名,Test2,3,4 為要添加的值得列名(不寫預設順序為建立表時的列的順序) 2,3,4 為具體的值update test set test2=xx where test2=xxx;          //修改(更新)test表中的資料,將合格test2例的值改為xx(不寫條件會預設修改整個test2列的值為xx)   delete test1 from test where test1=xx              //同上,刪除合格test表中的test1列的值(預設刪除test1列全部的值)

 

oracle資料庫小總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.