- 查看数据库
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 # 删除用户