标签:
<span style="font-family:KaiTi_GB2312;font-size:18px;"><strong>create table emp1 as select employee_id , last_name , hire_date , salary from employees where 1 = 2</strong></span>
<span style="font-family:KaiTi_GB2312;font-size:18px;"><strong>insert into emp1 values(1001,'abc',to_date('1998-12-11','yyyy-mm-dd'),10000)</strong></span>
<span style="font-family:KaiTi_GB2312;font-size:18px;"><strong>insert into emp1 values(1002,'c',to_date('1999-01-11','yyyy-mm-dd'),null)注意,salary不写,是不可以的 </strong></span>
<span style="font-family:KaiTi_GB2312;font-size:18px;"><strong>insert into emp1(employee_id,last_name,hire_date) values(1004,'c1',to_date('2999-05-11','yyyy-mm-dd'))</strong></span>
<span style="font-family:KaiTi_GB2312;font-size:18px;"><strong>insert into emp1(employee_id , hire_date , last_name , salary) select employee_id , hire_date , last_name , salary from employees where department_id = 80</strong></span>
<span style="font-family:KaiTi_GB2312;font-size:18px;"><strong>insert into emp1(employee_id , last_name , salary ,hire_date) values(&id,'&name',&salary,'&hire_date')</strong></span>
<span style="font-family:KaiTi_GB2312;font-size:18px;"><strong>SQL> update emp1 2 set 3 salary = 12000 4 where employee_id = 1005;//注意不写where会把所有的数据都改掉 (commit;保存)</strong></span>
<span style="font-family:KaiTi_GB2312;font-size:18px;"><strong>create table empployees1 as select * from employees update empployees1 set job_id = ( select job_id from empployees1 where employee_id = 205 ),salary = ( select salary from empployees1 where employee_id = 205 ) where employee_id = 114;</strong></span>
<span style="font-family:KaiTi_GB2312;font-size:18px;"><strong>update empployees1 set department_id = ( select department_id from empployees1 where employee_id = 100 ) where job_id = ( select job_id from empployees1 where employee_id = 200 )</strong></span>
delete from...
where....
从emppployees1表中删除部门名称中含public字符的部门id
<span style="font-family:KaiTi_GB2312;font-size:18px;"><strong>delete from empployees1 where department_id = ( select department_id from departments where department_name like '%Public%' )</strong></span>
<span style="font-family:KaiTi_GB2312;font-size:18px;"><strong>(1)insert into...values(...) (2)insert into... select ..from .. where ... </strong></span>
<span style="font-family:KaiTi_GB2312;font-size:18px;"><strong>update ..set ..where ..</strong></span>
<span style="font-family:KaiTi_GB2312;font-size:18px;"><strong>delete from ..where ..</strong></span>
一组逻辑操作单元,使数据从一种状态变换到另一种状态。
数据库事务由以下的部分组成:
一个或多个DML 语句
一个 DDL(Data Definition Language 数据定义语言) 语句
一个 DCL(Data Control Language 数据控制语言) 语句
以第一个 DML 语句的执行作为开始
以下面的其中之一作为结束:
COMMIT 或 ROLLBACK 语句
DDL 语句(自动提交)
rollback,回滚的是最后一次的commit
提交或回滚前的数据状态
改变前的数据状态是可以恢复的
执行 DML 操作的用户可以通过 SELECT 语句查询之前的修正
其他用户不能看到当前用户所做的改变,直到当前用户结束事务。
DML语句所涉及到的行被锁定, 其他用户不能操作。
这个类似于多线程操作共享数据,当一个线程在操作改数据时,如果它不释放锁,其他线程是无法操作这个数据的
scott用户正在update表,没有commit
system用户
select * from scott.employees for update;
就无法查询,处于等待状态,等到scott用户commit了,就可以查询了
这时scott用户还想继续修改表,就不行了,因为要等system用户commit
标签:
原文地址:http://blog.csdn.net/wjw0130/article/details/43453027