Oracle的一些常用操作____Oracle

來源:互聯網
上載者:User
一、許可權相關

1. 登陸

sqlplus system/admin as sysdba; //管理員身份登陸system帳戶

sqlplus scott/tiger; //登陸普通使用者scott   

2. 系統管理使用者

create user wahaha; //在系統管理員帳戶下,建立使用者zhangsan       
alert user scott identified by tiger; //修改密碼   
create user zhangsan; //在系統管理員帳戶下,建立使用者zhangsan   
alert user scott identified by tiger; //修改密碼 


3. 授予許可權

/*管理員授權*/      
grant create session to wahaha; //授予zhangsan使用者建立session的許可權,即登陸許可權,都要有       
grant unlimited session to wahaha; //授予zhangsan使用者使用資料表空間的許可權       
grant create table to wahaha; //授予建立表的許可權       
grante drop table to wahaha; //授予刪除表的許可權       
grant insert table to wahaha; //插入表的許可權       
grant update table to wahaha; //修改表的許可權       
grant all to public; //這條比較重要,授予所有許可權(all)給所有使用者(public)     


/*oralce對許可權管理比較嚴謹,普通使用者之間也是預設不能互相訪問的*/      
grant select on tablename to wahaha; //授予zhangsan使用者查看指定表的許可權       
grant drop on tablename to wahaha; //授予刪除表的許可權       
grant insert on tablename to wahaha; //授予插入的許可權       
grant update on tablename to wahaha; //授予修改表的許可權       
grant insert(id) on tablename to wahaha;       
grant update(id) on tablename to wahaha; //授予指定表特定欄位的插入和修改許可權,注意,只能是insert和update 
grant alert all table to wahaha; //授予zhangsan使用者alert任意表的許可權   


4. 撤銷許可權 
基本文法同grant,關鍵字為revoke 

5. 查看許可權

select * from user_sys_privs; //查看目前使用者所有許可權       
select * from user_tab_privs; //查看所用使用者對錶的許可權     
select * from user_sys_privs; //查看目前使用者所有許可權   
select * from user_tab_privs; //查看所用使用者對錶的許可權  


6. 授予使用者管理員權限
create user songuo identified by admin;
grant create session to songuo with admin option;
gran umlimited tablespace to songuo with admin option;
grant dba to songuo with admin option;


二、 表結構

1. 增加欄位

ALTER TABLE products ADD description text;

也可以同時在該欄位上定義約束:

ALTER TABLE products ADD  description text CHECK (description <> '100');


2.  刪除欄位

ALTER TABLE products DROP COLUMN description [CASCADE];


3. 增加約束

要增加一個約束,使用資料表條件約束文法, 如:
ALTER TABLE products ADD CHECK (name <> '');
ALTER TABLE products ADD CONSTRAINT some_name UNIQUE (product_no);
ALTER TABLE products ADD FOREIGN KEY (product_group_id) REFERENCES product_groups;
ALTER TABLE Teacher add constraint df_sex default('男') for sex


要增加一個不能寫成資料表條件約束的非空約束,使用下面文法:
ALTER TABLE products ALTER COLUMN product_no SET NOT NULL;
這個約束將立即進行檢查,所以表在添加約束之前必須符合約束條件。


4. 刪除約束

ALTER TABLE products DROP CONSTRAINT some_name [CASCADE];

刪除非空類型:
ALTER TABLE products ALTER COLUMN product_no DROP NOT NULL;


5. 修改一個欄位的資料類型

ALTER TABLE   表名   modify(欄位名   varchar2(20),   欄位名   varchar2(50))
ALTER TABLE products ALTER COLUMN price TYPE numeric(10,2);


6. 給欄位改名字
ALTER TABLE products RENAME COLUMN product_no TO product_number;


8、給表改名字

ALTER TABLE products RENAME TO items;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.