Oracle的基本使用

來源:互聯網
上載者:User

標籤:欄位   student   pre   art   null   xxxx   const   logs   _id   

學習來源:  http://www.jb51.net/article/45539.htm

       http://blog.csdn.net/j958703732/article/details/11066935

1. 建立資料表

文法:create table 表名 ( 欄位1  資料類型,欄位2  資料類型,...)  tablespace 資料表空間

create table STUDENT(    student_ID         NUMBER    not null,    student_NAME    VARCHAR2(20),    student_AGE     NUMBER,    status             VARCHAR2(2),    version            NUMBER    default    0)tablespace users----tablespace  用來指定資料表空間

①查看資料表的資料表空間資訊

通過視圖 user_tables 可以獲得目前使用者所擁有的表資訊,利用如下SQL語句可以查看錶 student 的資料表空間資訊。

select  table_name, tablespace_namefrom    user_tableswhere   upper(table_name) = ‘STUDENT‘;

②查看資料表的表結構

----使用 describe 來查看資料表的表結構desc student;

③表的重新命名

文法:alter  table  原表名  rename  to  新表名 ; 

 2. 添加新欄位

文法:alter  table  表名  add (欄位名  欄位類型  [default value],.....);

3. 修改欄位

修改欄位類型:alter  table  表名  modify (欄位名  欄位類型 [default value][null / not null],..... );

欄位重新命名:alter  table  表名  rename  column  原欄位名  to  新欄位名 ; 

4. 刪除欄位

文法:alter  table  表名  drop  column  欄位名 ; 

5. 主鍵

①主鍵可以在建立表的同時進行建立,主鍵可以有名字,也可以沒有名字

------1.建立有主鍵,但主鍵沒有名字的表格create  table  student(student_ID    int  primary key  not null,student_NAME  VARCHAR2(8),student_AGE   NUMBER,);------刪除無名主鍵:沒有主鍵名,需要先擷取select  *from    user_cons_columns;------上述SQL可得到 student 表的主鍵名 為 XXXXX(由系統命名),再刪除alter  table  student  drop  constraint  XXXXX;
-----2.建立有主鍵,且主鍵有名字的表格create table student(student_ID      int,student_NAME    VARCHAR2(8),student_AGE     NUMBERconstraint     keyName    primary key(student_ID));-----2.刪除有名主鍵:無需尋找,直接刪除alter  table  student  drop  constrain  keyName;
------3.向表中指定主鍵alter  table  student  add  constraint  keyName  primary key(student_ID);

6. 修改資料表的資料表空間資訊

修改意在將表移至其他資料表空間,以防最初建立時,資料表空間資訊錯誤

文法:drop  table  student  move  tablespace  users;

7. 刪除資料表

------1.刪除無外鍵約束的資料表drop  table  student;------2.刪除有外鍵約束的資料表drop  table  student  cascade  constraints ;

.

 

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.