oracle建立、刪除 資料庫、建立資料表空間以及插入 刪除 修改表

來源:互聯網
上載者:User

標籤:

一、建立、刪除資料庫

oracle OraDb11g_home->配置和移植工具->Database configration  Assistant->...然後可以建立或者刪除資料庫

二、建立資料表空間

create tablespace inspur_tablespace  

logging  

datafile ‘D:\MyOracleBACK SQL\StudentDB\inspur_tablespace.dbf‘ 

size 50m  

autoextend on  

next 50m maxsize 20480m  

extent management local;  

三、建立使用者 並指定資料表空間

create user username identified by password  

default tablespace inspur_tablespace  

【temporary tablespace user_temp方括弧中指定暫存資料表空間可有可無】;  

 

四、給使用者指派許可權

grant connect,resource,dba to username;  

五、建立表並指定主鍵和外鍵

在建立表格時就指定主鍵和外鍵
create table T_STU  (
   STU_ID               char(5)                         not null,
   STU_NAME             varchar2(8)                     not null,
   constraint PK_T_STU primary key (STU_ID)
);

//給表添加備忘
comment on table OT_STU  is ‘該表是學生資訊表’

//給列添加備忘
comment on columm OT_STU.STU_ID  is ‘學生標識’
//查看列備忘  這時候要標註表名稱以及列名稱
select * from table OT_STU where TABLE_NAME=’table OT_STU’ and column_name=‘STU_ID 

主鍵和外鍵一起建立:
create table T_SCORE  (
   EXAM_SCORE           number(5,2),
   EXAM_DATE            date,
   AUTOID               number(10)                      not null,
   STU_ID               char(5),
   SUB_ID               char(3),
   constraint PK_T_SCORE primary key (AUTOID),
   constraint FK_T_SCORE_REFE foreign key (STU_ID)
      references T_STU (STU_ID)
)

 

六、修改表

(1)添加一個欄位

alter table tablename1  add (columname number(2));

(2)修改欄位的長度

alter table tablename1 modify(columname1 varchar2(30));

(3)修改欄位的名字或者類型(不能有數字)

alter table tablename1 modify(columname1 char(20) );

(4)刪除一個欄位

alter table tablename1 drop column columname1;

(5)修改表的名字

rename  tablename1 to tablename2;

(6)刪除表

drop table tablename2;

(7)添加主鍵

alter table GUM_POLICE_INFO2
add primary key (ID);

七、常用插入語句

Insert into 表名(欄位名即屬性)values(你想要插入屬性的值); 
查詢語句和其他資料庫一樣

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.