SQL_DML简单操作

2015-07-24 11:29:55 · 作者: · 浏览: 5

***********************************************声明***********************************************************************

原创作品,出自 “深蓝的blog” 博客,欢迎转载,转载时请务必注明出处,否则追究版权法律责任。

深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/39903951

****************************************************************************************************************************

SQL基础之简单的DML语句

--查看实验表原始数据
SQL> select * from newdept;
NEWDEPTNO OLDDEPTNO NEWDNAME OLDDNAME NEWLOC OLDLOC
--------- --------- -------------- -------------- ------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON

查看某一列的数据量
SQL> select count(*) from newdept where oldloc is not null;
COUNT(*)
----------
4

(1)、update

update 表名 set列名=值 [,列名=值,...] [where 条件]

例:
SQL> update newdept set newdeptno=08,newdname='BUSINESS',newloc='BEIJING' where olddeptno=30;
--更新一条数据操作
1 row updated

SQL> select * from newdept;
NEWDEPTNO OLDDEPTNO NEWDNAME OLDDNAME NEWLOC OLDLOC
--------- --------- -------------- -------------- ------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
8 30 BUSINESS SALES BEIJING CHICAGO
40 OPERATIONS BOSTON

(2)、delete

delete [from] 表名 [where 条件]

SQL> delete from newdept where olddeptno=10;
--删除一条数据操作
1 row deleted

SQL> select * from newdept;
NEWDEPTNO OLDDEPTNO NEWDNAME OLDDNAME NEWLOC OLDLOC
--------- --------- -------------- -------------- ------------- -------------
20 RESEARCH DALLAS
8 30 BUSINESS SALES BEIJING CHICAGO
40 OPERATIONS BOSTON

(3)、insert

insert into 表名 [(列名 [,列名...])] values (数值 [,数值...]);
SQL> insert into newdept values (1,'','BDA','','BEIJING','');
--插入一条数据操作
1 row inserted

SQL> select * from newdept;
NEWDEPTNO OLDDEPTNO NEWDNAME OLDDNAME NEWLOC OLDLOC
--------- --------- -------------- -------------- ------------- -------------
20 RESEARCH DALLAS
8 30 BUSINESS SALES BEIJING CHICAGO
40 OPERATIONS BOSTON
1 BDA BEIJING

把一个列插入到新的表中
--把scott用户的emp表的SAL列插入到hyl用户的newdept表中

***********************************************声明***********************************************************************

原创作品,出自 “深蓝的blog” 博客,欢迎转载,转载时请务必注明出处,否则追究版权法律责任。

深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/39903951

****************************************************************************************************************************