设为首页 加入收藏

TOP

SQL_DML简单操作
2015-07-24 11:29:55 来源: 作者: 【 】 浏览:3
Tags:SQL_DML 简单 操作

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

原创作品,出自 “深蓝的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

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

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇阿庆SQL智能查询分析器,使用delph.. 下一篇postgreSQL中含有PM/AM时间格式转..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·nginx 监听一个端口 (2025-12-25 00:19:30)
·整个互联网就没有一 (2025-12-25 00:19:27)
·囧次元最新官网入口 (2025-12-25 00:19:24)
·如何利用Python做数 (2025-12-24 23:48:36)
·如何使用python进行 (2025-12-24 23:48:34)