Oracle資料庫基礎總結
1.建表
CREATE TABLE orderdetail (
id number(11) NOT NULL PRIMARY KEY,
orders_id number(11) NOT NULL,
items_id number(11) NOT NULL,
items_num number(11) DEFAULT NULL,
CONSTRAINT FK_orderdetail_1 FOREIGN KEY (orders_id) REFERENCES orders (id),
CONSTRAINT FK_orderdetail_2 FOREIGN KEY (items_id) REFERENCES items (id)
);
2.插入資料
insert into users(id,username,birthday,sex,address) values (10,'張三',to_date('2014-02-
14','yyyy-mm-dd'),'1','北京市');
3.Oracle的保留字可以在以DBA身份登入的情況下,通過“select * from v$reserved_words order by keyword asc”語句來獲得。
4.建立表空間
create tablespace 表空間名
datafile 'D:\java\Oracle\product\10.1.0\oradata\zznorcl\hoteldata.dbf'//為表空間存放的物理路徑
size 200m //設定空間初始值大小
autoextend on next 10m maxsize unlimited; //表空間自動增長,每次變大 ~沒有最大限制
eg
datafile 'D:\oracle\hoteldata.dbf'
size 200m
autoextend on next 10m maxsize unlimited;
5.連線資料庫
sqlplus 使用者名稱/密碼@IP地址/資料庫名 eg:sqlplus sys/[email protected]/orcl
6.匯出表
(1)將資料庫TEST完全匯出,使用者名稱system 密碼manager 匯出到D:\daochu.dmp中
exp system/[email protected] file=d:\daochu.dmp full=y
(2) 將資料庫中system使用者與sys使用者的表匯出
exp system/
7.匯入表
(1)將D:\daochu.dmp 中的資料匯入TEST資料庫中。
imp system/[email protected] file=d:\daochu.dmp
imp sys/[email protected] full=y file=file= d:\data\newsmgnt.dmp ignore=y
上面可能有點問題,因為有的表已經存在,然後它就報錯,對該表就不進行匯入。在後面加上ignore=y 就可以了。
(2)將d:\daochu.dmp中的表table1 匯入
imp system/[email protected] file=d:\daochu.dmp tables=(table1)