Oracle資料庫常用的語法

2021-10-02 02:23:16 字數 3610 閱讀 1428

oracle資料庫的入門

oracle的簡介:

oracle資料庫基於客戶端/伺服器技術

資料庫伺服器對資料表進行最佳管理,處理多個客戶端的同一資料的併發訪問。全面地保持完整性,並控制資料庫訪問許可權等安全性要求

oracle資料庫的主要特點:

支援多使用者、大事務量的事務處理

資料安全性和完整性控制

支援分布式資料處理

可移植性

資料庫的邏輯結構是從邏輯角度分析資料庫的組成。

oracle的邏輯元件包括:

資料庫 ----->表空間----->段----->區----->資料塊

段是構成表空間的邏輯儲存結構,端遊一組區組成。

按照段所儲存資料的特徵,將段分為四種型別,即資料段、索引段、回退段和臨時段。

區為段分配空間,它由連續的資料塊組成。

當段中的所有空間已完成是使用時,系統自動為該段分配乙個新區

去不能跨資料檔案存在,只能存在於乙個資料檔案中。

資料塊

資料塊是oracle伺服器所能分配、讀取或寫入的最小儲存單元。

oracle伺服器一資料塊為單位管理資料檔案的儲存空間

模式

模式是對使用者所建立的資料庫物件的總稱。

模式物件包括表、檢視、索引、同義詞、序列、過程和程式包等。

oracle預設使用者

sqlplus scott/tiger;

-- scott使用者登入

conn system/manager;

--system使用者重新登陸

conn /

as sysdba;

-- sys使用者重新登陸

alter

user scott account unlock

;--將scott使用者解鎖

** scott使用者預設能訪問的表emp*

*select

*from emp;

set linesize 150

; 設定每行字元數

set pagesize 10; 設定每頁顯示10行的資料

desc emp;檢視表emp的結構

show

user; 檢視當前使用者

conn system/tigter; system使用者重新登陸

conn /

as sysdba; sys使用者重新登陸

表空間操作

-- 切使用者,scott無建立表空間的許可權

conn /

as sysdba;

-- 建立表空間

create

tablespace 表空間名稱 datafile '表空間位址' size 50m autoextend on

;create

tablespace super datafile 'd:\work\oracle work\super.dbf' size 50m autoextend on

;-- 修改表空間的名稱

alter

tablespace 舊表空間名稱 rrname to 新錶空間名稱

-- 擴充套件表空間,新增資料檔案

alter

tablespace 表空間名稱 add datafile '表空間位址' size 50m;

-- 檢視當前資料庫的自由表空間

select

*from dba_free_space;

-- 檢視當前使用者的自由表空間

select

*from user_free_space;

-- 允許表空間的資料檔案自動擴充套件

alter

database datafile '表空間位址' autoextend on

next

10m maxsize 20m;

-- 使表空間離線,離線後則改表空間不可用,在系統表user_free_space 和 dba_free_space

alter

tablespace 表空間名稱 offline;

-- 使用表空間

alter

tablespace 表空間名稱 online;

-- 刪除表空間

drop

tablespace 表空間名稱;-- 表空間中無物件

建立新使用者

create

user 使用者名稱 identifiedby 密碼(以字母開頭)

[default

tablespace 預設表空間名稱(預設訪問的表空間)][

temporary

tablespace 臨時表空間名稱]

;

授予許可權

-- 授予許可權qgrant命令可用於為使用者分配許可權或角色grantconnectto使用者名稱;connect角色允許使用者連線至資料庫,並建立資料庫物件

grant

connect

to 使用者名稱;

-- resource角色允許使用者使用資源的許可權,例如建立表、查詢資料.....

grant resource to 使用者名稱;

-- 賦予使用者建立表空間的許可權

grant

create

tablespace

to 使用者名稱;

-- 允許使用者查詢test表的記錄

grant

select ontest to tom;

-- 允許使用者更新test表中的記錄

grant

update ontest to tom;

-- 允許使用者插入、刪除、更新和查詢test表中的記錄

grant

allon test to tom;

-- tom訪問system(使用者)模式下的某錶

select

*from system.表名;

-- tom訪問sysdba(使用者)模式下的某錶

select

*from sys.表名;

資料控制語言

revoke	系統許可權	from	使用者名稱;

或revoke 系統許可權 on 物件名 from 使用者名稱;

更改和刪除使用者

-- alter	user	命令可用於更改口令

-- 修改 使用者密碼

alter

user 使用者名稱 identified by 新密碼;

-- dropuser命令用於刪除使用者

-- 當使用者下有表或其它物件時,需要新增cascade關鍵字,級聯刪除物件 。刪除使用者

drop

user 使用者名稱 [

cascade

];

常用的資料庫語法

1建立資料庫 create database database name 2刪除資料庫 drop database dbname 3建立表create table table name id number,name varchar,varchar,age number 4刪除表 drop table...

Oracle資料庫常用語法總結

二 表及資料複製 建立表 create table test id varchar 50 not null name varchar 50 null 建立檢視 create orreplace view vw test as select from test1 left join test12 on...

oracle資料庫語法大全

鎖定賬戶 alter user scott account lock 解鎖賬戶 alter user scott account unlock 建立使用者及密碼 create user mm identified by 123 修改使用者密碼 alter user mm identified by ...