- 查看數據庫
select * from v$database
- 查看當前用戶的表
select * from user_tables select table_name,tablespace_name from user_tables #查看錶以及其命名空間
- 查看錶空間
select * from dba_tablespaces
- 查看全部的用戶
select * from dba_user select username,default_tablespace from dba_users #查看用戶以及對應的表空間
- 子查詢
in 、any 、>、<、=、>=、<=、<>
in : 等於列表中如何值
select * from sm where salary in(100,300,400)
any:跟子查詢每一個值比較,(小於最大,大於最小)sql
select * from sm where salary < any(select salary from employ)
-
增長一列
alter table tb add ( col type,.....)數據庫 -
刪除表字段
alter table tb drop column(col1.....)spa -
約束條件 constraint
用法 constraint 約束名 約束條件 (字段)
支持的約束條件:
Not NULL
unique
primary key
foreign keycode
create table tb ( col1 datatype, col2 datatype, .... coln datatype, constraint fk foreign key(col1...coln) references parent_table(col1...coln) )
on delete cascade :主表的行被刪除時,外鍵依賴的字表對應的行也要刪除
on delete set null :主表的行被刪除時,外鍵依賴的字表對應的行值置爲空
check :定於每一行必須知足的條件索引
create table tb ( salary number(10,2), constraint ck check(salary > 0) )
- 建立索引
create index index_name on table_name(col_name)
- 用戶
create user t_user indentified by "123" #建立用戶 drop user t_user # 刪除用戶