基本查詢

  1. 查看數據庫
select * from v$database
  1. 查看當前用戶的表
select * from user_tables     
select table_name,tablespace_name from user_tables  #查看錶以及其命名空間
  1. 查看錶空間
select * from dba_tablespaces
  1. 查看全部的用戶
select * from dba_user  
select username,default_tablespace from dba_users   #查看用戶以及對應的表空間
  1. 子查詢
    in 、any 、>、<、=、>=、<=、<>
    in : 等於列表中如何值
select * from sm where salary in(100,300,400)

any:跟子查詢每一個值比較,(小於最大,大於最小)sql

select * from sm where salary < any(select salary from  employ)
  1. 增長一列
    alter table tb add ( col type,.....)數據庫

  2. 刪除表字段
    alter table tb drop column(col1.....)spa

  3. 約束條件 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)   
)
  1. 建立索引
create index index_name on table_name(col_name)
  1. 用戶
create user t_user indentified by "123"    #建立用戶   
drop user t_user   # 刪除用戶
相關文章
相關標籤/搜索