1、创建表以及添加表注释和字段注释
create table student(
student_number varchar2(10),
student_name varchar2(10),
sex varchar2(4),
score number(4)
);
comment on table student is '学生信息表';
comment on column student.student_number is '学生学号';
comment on column student.student_name is '学生姓名';
comment on column student.sex is '性别';
2、ALTER TABLE
//添加俩个字段grade和class
alter table student add (grade varchar2(10),class varchar2(10));
//删除grade
alter table student drop column grade;
//修改字段名或表名
alter table student rename to student_new;
alter table student rename column class to class_new;
//修改字段类型和大小
alter table student modify(class number(10));
//增加删除启用禁用约束
alter table student add constraint 约束名称 主键或外键等(字段)
alter table student drop constraint 约束名称
alter table student enable constraint 约束名称
alter table student disable constraint 约束名称
3、UPDATE TABLE
//把student的name字段的值全部设为张一山
update student set name = '张一山'
//找到student_number = '111000'对应的name,把name为张一山
update student set student_name = '张一山' where student_number = '111000'
//update语句的set子句支持同时将多个列作为更新对象。使用逗号将列进行分隔排列,这一方法
在所有的DBMS 中都可以使用。
update student set score = score + 10,sex = '男'
//同一张表,一个字段的数据更新到另一个字段(注意字段类型要相同)
update student set student_name = student_number
//不同表,一张表的一个字段更新到另一张表的一个字段
/*
假设有另一张表student_subject的name字段数据是正确的,而student的name字段数据存在错误,现在
我们就需要把正确的数据更新到(或者说覆盖到)错误的数据中,where条件保证了学号相等的时候name字段才会覆盖。
*/
update student set name = (select name from student_subject where student.学号 = student_subject.学号)
//
INSERT语句
//注意下面俩种插入方式的不同,可以选择字段插入
insert into student values('111000','张三','男','68')
insert into student(student_number,student_name) values('111000','张三')
//同一个表,一个字段插入到另一个字段
/*
这里是把学号的数据插入到姓名中,用update也可以做到,这种情况下用insert要注意被插入的字段没有数据才行
*/
insert into student(student_name) select 学号 from student
//不同表一个字段插入到另一个字段
如果表结构相同:insert into 表1 select * from 表2
如果表结构不同:insert into 表1(字段1,字段2,.....) select 字段1,字段2,..... from 表2
//
DELETE语句与DROP语句
//删除表中所有记录,清空数据
delete from 表名
//删除表中某一行
delete from 表名 where 条件
//删除整个表
drop table 表名
//删除整个用户
/*
cascade表示级联,意思是删除用户的同时,删除用户下的所有数据对象,如表....
*/
drop user 用户名 cascade