一、數(shù)據(jù)庫操作
1、創(chuàng)建數(shù)據(jù)庫
2、刪除數(shù)據(jù)庫
drop
3、備份數(shù)據(jù)庫
exp demo/demo@orcl =1024 file=d:\back.dmp full=y
demo:用戶名、密碼
:緩存大小
file:具體的備份文件地址
full:是否導出全部文件
:忽略錯誤,如果表已經(jīng)存在,則也是覆蓋
exp demo/demo@orcl file=d:\\1.dmp owner=(,sys)
exp demo/demo@orcl file=d:\.dmp =(,)
exp demo/demo@orcl file=d:\back.dmp =() query=\" where like 'fg%'\"
導出時可以進行壓縮;命令后面 加上 =y ;如果需要日志,后面: log=d:\log.txt
exp 用戶名/密碼@遠程的IP:端口/實例 file=存放的位置:\文件名稱.dmp full=y
4、數(shù)據(jù)庫還原
打開cmd直接執(zhí)行如下命令,不用再登陸。
imp demo/demo@orcl file=d:\back.dmp full=y =y log=D:\.txt
指定log很重要,便于分析錯誤進行補救。
imp demo/demo@orcl file=d:\.dmp =(,)
imp 用戶名/密碼@遠程的IP:端口/實例 file=存放的位置:\文件名稱.dmp full=y
二、表操作
1、創(chuàng)建表
table (col1 type1 [not null] [ key],col2 type2 [not null],..)
根據(jù)已有的表創(chuàng)建新表:
A: * into from (使用舊表創(chuàng)建新表)
B: table as col1,col2… from only
2、刪除表
drop table
3、重命名表
說明:alter table 表名 to 新表名
eg:alter table to
4、增加字段
說明:alter table 表名 add (字段名 字段類型 默認值 是否為空);
例:alter table add (ID int);
alter table (ID (30) '空' not null);
5、修改字段
說明:alter table 表名 (字段名 字段類型 默認值 是否為空);
eg:alter table (ID (4));
6、重名字段
說明:alter table 表名 列名 to 新列名 (其中:是關鍵字)
eg:alter table ID to newID;
7、刪除字段
說明:alter table 表名 drop 字段名;
eg:alter table ID;
8、添加主鍵
alter table add key(col)
9、刪除主鍵
alter table drop key(col)
10、創(chuàng)建索引
[] index on (col….)
11、刪除索引
drop index
注:索引是不可更改的,想更改必須刪除重新建。
12、創(chuàng)建視圖
view as
13、刪除視圖
drop view
三、操作數(shù)據(jù)
1、數(shù)據(jù)查詢
from [where ] [order by [asc或desc]]
2、插入數(shù)據(jù)
into 表名 (所有列的值);
into test (1,'',20);
into 表名(列) (對應的值);
into test(id,name) (2,'lisi');
3、更新數(shù)據(jù)
表 set 列=新的值 [where 條件] -->更新滿足條件的記錄
test set where
表 set 列=新的值 -->更新所有的數(shù)據(jù)
test set age =20;
4、刪除數(shù)據(jù)
from test where id = 1;
from test -->刪除所有
; -->提交數(shù)據(jù)
; -->回滾數(shù)據(jù)
方式可以恢復刪除的數(shù)據(jù),但是提交了數(shù)據(jù)庫刪除記錄語句,就沒辦法了 刪除的時候,會記錄日志 -->刪除會很慢很慢
刪除所有數(shù)據(jù),不會影響表結(jié)構(gòu),不會記錄日志,數(shù)據(jù)不能恢復 -->刪除很快
刪除所有數(shù)據(jù)數(shù)據(jù)庫刪除記錄語句,包括表結(jié)構(gòu)一并刪除,不會記錄日志,數(shù)據(jù)不能恢復-->刪除很快
5、數(shù)據(jù)復制
into ( * from );
table * from where 1>1;
table * from ;
table as id, name from where 1>1;
四、數(shù)據(jù)庫復制命令
看完本文有收獲?請轉(zhuǎn)發(fā)分享給更多人
關注「數(shù)據(jù)庫開發(fā)」,提升 DB 技能