標籤:
一、建立、刪除資料庫
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建立、刪除 資料庫、建立資料表空間以及插入 刪除 修改表