Oracle下SQL基本操作 一

2021-12-29 20:14:46 字數 4075 閱讀 9355

--建立永久表空間

create tablespace "58space"

logging

datafile 'd:\oracle\oradata\mydb\57space.ora' size 5m extent

management local segment space management  auto

--建立臨時表空間   

create

temporary tablespace "58tmpspace" tempfile

'd:\oracle\oradata\mydb\58tmpspace.ora' size 5m extent management

local uniform size 2m

--建立使用者

create user "58user"

identified by "123456"--指定口令

default tablespace "58space"--分配永久表空間

temporary tablespace "58tmpspace"--分配臨時表空間

quota unlimited on "58space";--分配使用表空間的許可權

--sql command

--使用者從客戶端登入資料庫

conn 58user/123456@mydb;

conn system/system@mydb;

--建立角色

create role "58role";

create role "testrole";

--授權

grant alter any table to "58role";

grant alter any table to "58role" with admin option;

revoke alter any table from "58role";

grant connect to "58user" with admin option;

revoke connect from "58user";

grant resource to "58user";

grant connect to "testrole";

--建立永久表空間

create tablespace "62space"

logging

datafile 'd:\oracle\oradata\mydb\62space.ora' size 5m extent

management local segment space management  auto

--建立臨時表空間   

create

temporary tablespace "62tmpspace" tempfile

'd:\oracle\oradata\mydb\62tmpspace.ora' size 5m extent management

local uniform size 2m

--建立使用者

create user "62user"

identified by "123456"--指定口令

default tablespace "62space"--分配永久表空間

temporary tablespace "62tmpspace"--分配臨時表空間

quota unlimited on "62space";--分配使用表空間的許可權

--sql command

--使用者從客戶端登入資料庫

connect 62user/123456@mydb;

conn system/system@mydb;

--建立角色

create role "62role";

create role "testrole";

--授權

grant alter any table to "62role";

grant alter any table to "62role" with admin option;

revoke alter any table from "62role";

grant connect to "62user" with admin option;

grant connect to "58user";

--取消許可權或角色

revoke connect from "62user";

grant resource to "62user";

grant connect to "testrole";

--檢視系統檢視

select * from user_tablespaces;

select * from user_objects;

select * from user_constraints;

--建立表

create table student(

id char(10),

name varchar2(40) not null,

*** char(1) constraints stu_***_nn not null,

birthday date,

constraints stu_id_pk primary key (id)

); create table degreedd (

id char(10),

cid char(4),

score number(4, 1)

);  

--刪除表

drop table degree;

--新增約束

alter table degree

add constraints deg_idcid_pk primary key (id, cid);

--外來鍵約束

alter table degree

add constraints deg_id_fk foreign key (id) references student(id);

--check 約束

alter table degree

add constraints deg_sc_c check (score >= 60);

--unique

alter table degree

add constraints deg_cid_uk unique (cid);

--新增 not null

alter table degree

modify cid not null;

alter table degree

modify cid constraints deg_cid_nn not null;

--刪除約束

alter table degree

drop constraints sys_c003040;

--新增列

alter table student

add roomid char(4);

--sql command

desc student;

--刪除列

alter table student

drop column roomid;

--修改列的型別

alter table degree

modify cid varchar2(4);

--啟用/禁用約束

alter table degree

enable constraints deg_cid_nn;

alter table degree

disable constraints deg_cid_nn;

--修改列名

alter table degree

rename column cid to course;

--修改約束名

alter table degree

rename constraints deg_cid_nn to deg_cou_nn;

--修改表名

rename student to stu;

--截斷表,刪除資料的同時釋放該錶所占用的記憶體空間

truncate table stu;

本文出自 「enthusiasm   10年」 部落格

Oracle基本SQL操作

1 建立使用者並賦予許可權 sqlplus as sysdba 建立使用者 create user scaffold identified by scaffold 表空間分配給使用者 alter user scaffold default tablespace scaffold sql語句來檢視一下...

14 ORACLE下的基本SQL操作

oracle下的基本sql操作 1.獲取表字段 select from user tab columns where table name 使用者表 order by column name 2.獲取表注釋 select from user tab comments where table name...

linux下的oracle基本操作

1.su oracle 2.sqlplus logon 3.connect test test as sysdba test test是 oracle 使用者和密碼 4.startup 5.lsnrctl 首選啟動資料庫 su oracle sqlplus nolog conn as sysdba ...