1、查询语句:用于检索数据库表中存储的行,可以使用select语句编写查询语句
4、事务控制语句
select sysdate from dual;
2、数据操纵语言:用于修改表的内容
insert into customers values(112, 'jack', 18666210383);
//如果有默认值,有如下2中方法插入数据:
insert into customers values(112, 'jack', default);
insert into customers(customer_id,name) values(112, 'jack');
update customers set name='jacky' where phone=18666210383;
delete from customer where sex ='男';
delete from customer; --删除表中所有记录
3、数据定义语言(约束的添加和删除) /(truncate和delete的区别)
create table customer(
id integer constraint customer_pk primary key,
name varchar2(10) not null,
phone varchar2(10)
);
alter table customer rename to customers; --修改表名
alter table customers rename column id to customer_id; --修改列名
alter table customer modify phone varchar2(11); --修改字段类型
alter table customer add sex varchar2(2); --添加表列
alter table customers drop column sex; --删除表列
alter table customer add constraint sex_check check(sex in ('男','女')); --添加check约束
//如果在原有数据中,已经有sex不是男或女,下面的约束会添加失败,解决方法是将原有数据中不满足check的记录先删除,或者使用novalidate
alter table customer add constraint sex_check check(sex in ('男','女')) novalidate;
alter table customer drop constraint sex_check; --删除约束
alter table customers add constraint customer_id_pk primary key(customer_id); --添加主键约束
alter table customers add constraint phone_uq unique(phone); --添加唯一性约束
//开始使用alter table customers add constraint DF_sex default('男')for sex; 却失败了
alter table customers modify sex default '男'; --添加default约束
alter table student add constraint FK_cno foreign key(cno) references class(cno); --添加外键约束
rename oldtablename to newtablename; --修改表名
drop table tablename; --删除表
TRUNCATE TABLE table; --清空表
4、事务控制语句
commit : 永久性的保存对行所做的修改
rollback :阻止其他用户访问数据库结构(回收权限)
savepoint:设置一个保存点,可以将对行所做的修改回滚到此处
5、数据控制语言(grant和revoke1)(grant和revoke2)
grant:授予其他用户对数据库结构的访问权限
revoke:阻止其他用户访问数据库结构(回收权限)
grant connect, resource to jack;
revoke connect, resource from jack;