Oracle SQL基本用法
文章目录
表操作
-
创建表 create table tablename (age int,name String ……)
primary key (xxx,yyy)
foreign key (xxx) references 表名 (xxx)
-
删除表 drop table tablename cascade|restricty
修改基本表 ↓ alter table 表名
add column <新列名><数据类型>[完整性约束]
add 表级完整性约束
…
-
重命名表 alter table 表名 rename to 新表名
-
增加字段 alter table tablename add (ID int default ‘空’ not null)
-
修改字段 alter table tablename modify (ID varchar(4))
-
重命名字段 alter table tablename rename column 列名 to 新列名
-
删除字段 alter table tablename drop column 字段名
-
添加主键 alter table tablename add peimary key (col)
-
删除主键 alter table tablename drop primary key (col)
-
创建索引 create unique|cluster index idxname on tablename(col)
create unique index SCno on SC(Sno asc,Cno desc)
asc:升序
desc:降序
-
删除索引 drop index idxname (索引是不能改变的,再更改之前必须删除之前的索引 新建)
-
修改索引名 alter index 旧索引名 rename to 新索引名
-
创建模式 create schema 模式名 authorization 用户名
-
删除模式 drop schema 模式名 cascade|restrict
cascade和restrict必须选一个
cascade:将模式下的所有数据库对象一起删除
restrict:如果模式下有数据库对象,拒绝删除
数据查询
–完整语法描述:
select { [distinct | all] column | *} [into table_name] from { table | views | other select} [where conditions] [group by columns] [having conditions] [order by columns]
distinct : 去掉重复
字符匹配:
[not] like '匹配串' [escape '换码字符'] % : 表示任意长度的字符串 _ : 表示单个任意字符
select * from student where Sname like '刘%'; select * from student where Sname like '欧阳_';