DML 操作是指对数据库中表记录的操作,主要包括表记录的插入(insert)、更新(update)、删除(delete)和查询(select),是开发人员日常使用最频繁的操作。

插入记录

表创建好后,就可以往里插入记录了,插入记录的基本语法如下

INSERT INTO tablename (field1, field2, .…, fieldn)VALUES (value1, value2, ..……, valuen);

向表 emp 中插入:ename 为 zzx1,hiredate 为 2000-01-01,sal 为 2000,deptno 为 1

mysql> desc emp;
+----------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------+------+-----+---------+-------+
| ename | varchar(10) | YES | | NULL | |
| hiredate | date | YES | | NULL | |
| sal | decimal(10,2) | YES | | NULL | |
| deptno | int(2) | YES | | NULL | |
+----------+---------------+------+-----+---------+-------+
4 rows in set (0.01 sec) mysql> insert into emp(ename,hiredate,sal,deptno) values('zzx1','2000-01-01','2000',1);
Query OK, 1 row affected (0.01 sec)

也可以不用指定字段名称,但是 values 后面的顺序应该和字段的排列顺序一致

mysql> insert into emp values('lisa','2003-02-01','3000',2);
Query OK, 1 row affected (0.01 sec) mysql> insert into emp values('bjguan','2004-04-02','4000',1);
Query OK, 1 row affected (0.01 sec)

只对表中的 ename 和 sal 字段显式插入值

mysql> insert into emp(ename,sal) values('dony',1000);
Query OK, 1 row affected (0.01 sec)

查看实际插入的值

mysql> select * from emp;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx1 | 2000-01-01 | 2000.00 | 1 |
| lisa | 2003-02-01 | 3000.00 | 2 |
| bjguan | 2004-04-02 | 4000.00 | 1 |
| dony | NULL | 1000.00 | NULL |
+--------+------------+---------+--------+
4 rows in set (0.00 sec)

可以一次性插入多条记录,每条记录之间用逗号分隔

INSERT INTO tablename (field1, field2, ..…, fieldn)

VALUES

(record1_value1, record1_value2, .…, record1_valuen),

(record2_value1, record2_value2, .…, record2_valuen),

...

(recordn_value1, recordn_value2, .…, recordn_valuen);

首先创建表 dept

mysql> create table dept(deptno int(2), deptname varchar(10));
Query OK, 0 rows affected (0.03 sec) mysql> desc dept;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| deptno | int(2) | YES | | NULL | |
| deptname | varchar(10) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
2 rows in set (0.01 sec)

对 dept 表一次插入多条记录

mysql> insert into dept values(1,'tech'),(2,'sale'),(5,'fin'),(5,'dept5'),(6,'dept6');
Query OK, 5 rows affected (0.01 sec)
Records: 5 Duplicates: 0 Warnings: 0 mysql> select * from dept;
+--------+----------+
| deptno | deptname |
+--------+----------+
| 1 | tech |
| 2 | sale |
| 5 | fin |
| 5 | dept5 |
| 6 | dept6 |
+--------+----------+
5 rows in set (0.00 sec)

更新记录

UPDATE tablename SET field1=value1, field2=value2, ..., fieldn=valuen [WHERE CONDITION]

将表 emp 中 ename 为 “lisa” 的薪水(sal)从 3000 改为 4000

mysql> update emp set sal=4000 where ename='lisa';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from emp;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx1 | 2000-01-01 | 2000.00 | 1 |
| lisa | 2003-02-01 | 4000.00 | 2 |
| bjguan | 2004-04-02 | 4000.00 | 1 |
| dony | NULL | 1000.00 | NULL |
+--------+------------+---------+--------+
4 rows in set (0.00 sec)

update 命令可以同时更新多个表中的数据

UPDATE t1, t2, ..., tn set t1.field1=expr1, t2.field2=expr2, ..., tn.fieldn=exprn [WHERE CONDITION]

同时更新表 emp 中的字段 sal 和表 dept 中的字段 deptname

mysql> select * from emp;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx1 | 2000-01-01 | 100.00 | 1 |
| lisa | 2003-02-01 | 200.00 | 2 |
| bjguan | 2004-04-02 | 100.00 | 1 |
| dony | 2005-02-05 | 2000.00 | 4 |
+--------+------------+---------+--------+
4 rows in set (0.00 sec) mysql> select * from dept;
+--------+----------+
| deptno | deptname |
+--------+----------+
| 1 | tech |
| 2 | sale |
| 5 | fin |
+--------+----------+
3 rows in set (0.00 sec) mysql> update emp a, dept b set a.sal=a.sal*b.deptno, b.deptname=a.ename where a.deptno=b.deptno;
Query OK, 3 rows affected (0.01 sec)
Rows matched: 5 Changed: 3 Warnings: 0 mysql> select * from emp;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx1 | 2000-01-01 | 100.00 | 1 |
| lisa | 2003-02-01 | 400.00 | 2 |
| bjguan | 2004-04-02 | 100.00 | 1 |
| dony | 2005-02-05 | 2000.00 | 4 |
+--------+------------+---------+--------+
4 rows in set (0.00 sec) mysql> select * from dept;
+--------+----------+
| deptno | deptname |
+--------+----------+
| 1 | zzx1 |
| 2 | lisa |
| 5 | fin |
+--------+----------+
3 rows in set (0.00 sec)

删除记录

DELETE FROM tablename [where CONDITION]

将 emp 中 ename 为 “dony” 的记录全部删除

mysql> delete from emp where ename='dony';
Query OK, 1 row affected (0.01 sec) mysql> select * from emp;
+--------+------------+--------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+--------+--------+
| zzx1 | 2000-01-01 | 100.00 | 1 |
| lisa | 2003-02-01 | 400.00 | 2 |
| bjguan | 2004-04-02 | 100.00 | 1 |
+--------+------------+--------+--------+
3 rows in set (0.00 sec)

可以一次删除多个表的数据

DELETE t1, t2, ..., tn FROM t1, t2, ..., tn [WHERE CONDITION]

如果 from 后面的表名用别名,则 delete 后面也要用相应的别名,否则会提示语法错误

同时删除表 emp 和 dept 中 deptno 为 3 的记录

mysql> select * from emp;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx1 | 2000-01-01 | 100.00 | 1 |
| lisa | 2003-02-01 | 200.00 | 2 |
| bjguan | 2004-04-02 | 100.00 | 1 |
| bzshen | 2005-04-01 | 300.00 | 3 |
| dony | 2005-02-05 | 2000.00 | 4 |
+--------+------------+---------+--------+
5 rows in set (0.00 sec) mysql> select * from dept;
+--------+----------+
| deptno | deptname |
+--------+----------+
| 1 | tach |
| 2 | sale |
| 3 | hr |
| 5 | fin |
+--------+----------+
4 rows in set (0.00 sec) mysql> delete a,b from emp a,dept b where a.deptno=b.deptno and a.deptno=3;
Query OK, 2 rows affected (0.01 sec) mysql> select * from emp;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx1 | 2000-01-01 | 100.00 | 1 |
| lisa | 2003-02-01 | 200.00 | 2 |
| bjguan | 2004-04-02 | 100.00 | 1 |
| dony | 2005-02-05 | 2000.00 | 4 |
+--------+------------+---------+--------+
4 rows in set (0.00 sec) mysql> select * from dept;
+--------+----------+
| deptno | deptname |
+--------+----------+
| 1 | tach |
| 2 | sale |
| 5 | fin |
+--------+----------+
3 rows in set (0.00 sec)

查询记录

SELECT * FROM tablename [where CONDITION]

显示 emp 表中的全部记录

mysql> select * from emp;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx | 2000-01-01 | 2000.00 | 1 |
| lisa | 2003-02-01 | 4000.00 | 2 |
| bjguan | 2004-04-02 | 5000.00 | 1 |
+--------+------------+---------+--------+
3 rows in set (0.00 sec) mysql> select ename,hiredate,sal,deptno from emp;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx | 2000-01-01 | 2000.00 | 1 |
| lisa | 2003-02-01 | 4000.00 | 2 |
| bjguan | 2004-04-02 | 5000.00 | 1 |
+--------+------------+---------+--------+
3 rows in set (0.00 sec)

查询不重复的记录

将表中的记录去掉重复后显示出来,可以用distinct关键字来实现:

mysql> select ename,hiredate,sal,deptno from emp;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx | 2000-01-01 | 2000.00 | 1 |
| lisa | 2003-02-01 | 4000.00 | 2 |
| bjguan | 2004-04-02 | 5000.00 | 1 |
+--------+------------+---------+--------+
3 rows in set (0.00 sec) mysql> select distinct deptno from emp;
+--------+
| deptno |
+--------+
| 1 |
| 2 |
+--------+
2 rows in set (0.00 sec)

条件查询

查询所有 deptno 为 1 的记录

mysql> select * from emp;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx | 2000-01-01 | 2000.00 | 1 |
| lisa | 2003-02-01 | 4000.00 | 2 |
| bjguan | 2004-04-02 | 5000.00 | 1 |
+--------+------------+---------+--------+
3 rows in set (0.00 sec) mysql> select * from emp where deptno=1;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx | 2000-01-01 | 2000.00 | 1 |
| bjguan | 2004-04-02 | 5000.00 | 1 |
+--------+------------+---------+--------+
2 rows in set (0.00 sec)

多字段查询

mysql> select * from emp where deptno=1 and sal<3000;
+-------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+-------+------------+---------+--------+
| zzx | 2000-01-01 | 2000.00 | 1 |
+-------+------------+---------+--------+
1 row in set (0.00 sec)

排序和限制

SELECT * FROM tablename [WHERE CONDITION] [ORDER BY field1 [DESC | ASC], field2 [DESC | ASC], ..., fieldn [DESC | ASC]]

DESC:降序排列     ASC:升序排列

把 emp 表中的记录按照工资高低进行显示

mysql> select * from emp order by sal;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx | 2000-01-01 | 2000.00 | 1 |
| dony | 2005-02-05 | 2000.00 | 4 |
| lisa | 2003-02-01 | 4000.00 | 2 |
| bjguan | 2004-04-02 | 5000.00 | 1 |
+--------+------------+---------+--------+
4 rows in set (0.00 sec)

如果排序字段的值一样,则值相同的字段按照第二个排序字段进行排序,依次类推。如果只有一个排序字段,则这些字段相同的记录将会无序排列。

把 emp 表中的记录按照部门编号 deptno 字段排序

mysql> select * from emp order by deptno;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx | 2000-01-01 | 2000.00 | 1 |
| bjguan | 2004-04-02 | 5000.00 | 1 |
| lisa | 2003-02-01 | 4000.00 | 2 |
| dony | 2005-02-05 | 2000.00 | 4 |
+--------+------------+---------+--------+
4 rows in set (0.00 sec)

对于 deptno 相同的前两条记录,如果要按照工资由高到低排序,可以使用以下命令

mysql> select * from emp order by deptno,sal desc;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| bjguan | 2004-04-02 | 5000.00 | 1 |
| zzx | 2000-01-01 | 2000.00 | 1 |
| lisa | 2003-02-01 | 4000.00 | 2 |
| dony | 2005-02-05 | 2000.00 | 4 |
+--------+------------+---------+--------+
4 rows in set (0.00 sec)

对于排序后的记录,如果希望只显示一部分,而不是全部,这时,就可以使用 LIMIT 关键字来实现

SELECT ... [LIMIT offset_start, row_count]

其中 offset_start 表示记录的起始偏移量,row_count 表示显示的行数。

在默认情况下,起始偏移量为 0,只需要写记录行数就可以,这时,实际显示的就是前 n 条记录。例如,显示 emp 表中按照 sal 排序后的前 3 条记录:

mysql> select * from emp order by sal limit 3;
+-------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+-------+------------+---------+--------+
| zzx | 2000-01-01 | 2000.00 | 1 |
| dony | 2005-02-05 | 2000.00 | 4 |
| lisa | 2003-02-01 | 4000.00 | 2 |
+-------+------------+---------+--------+
3 rows in set (0.00 sec)

如果要显示 emp 表中按照 sal 排序后从第二条记录开始的 3 条记录,可以使用以下命令:

mysql> select * from emp order by sal limit 1,3;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| dony | 2005-02-05 | 2000.00 | 4 |
| lisa | 2003-02-01 | 4000.00 | 2 |
| bjguan | 2004-04-02 | 5000.00 | 1 |
+--------+------------+---------+--------+
3 rows in set (0.00 sec)

聚合

SELECT [field1, field2, ..., fieldn] fun_name

FROM tablename

[WHERE where_contition]

[GROUP BY field1, field2, ..., fieldn

WITH ROLLUP]]

[HAVING where_contition]

参数说明:

  • fun_name 表示要做的聚合操作,也就是聚合函数,常用的有 sum(求和)count(记数)max(最大值)min(最小值)avg(平均值)
  • GROUP BY 关键字表示要进行分类聚合的字段,比如要按照部门分类统计员工数量,部门就应该写在 group by 后面。
  • WITH ROLLUP 是可选语法,表明是否对分类聚合后的结果进行再汇总。
  • HAVING 关键字表示对分类后的结果再进行条件的过滤。

注意:having 和 where 的区别在于,having 是对聚合后的结果进行条件的过滤,而 where 是在聚合前就对记录进行过滤,如果逻辑允许,尽可能用 where 先过滤记录,这样因为结果集减小,将对聚合的效率大大提高,最后再根据逻辑看是否用 having 进行再过滤。

在 emp 表中统计公司人数

mysql> select count(1) from emp;
+----------+
| count(1) |
+----------+
| 4 |
+----------+
1 row in set (0.00 sec)

在此基础上,要统计各个部门的人数

mysql> select deptno,count(1) from emp group by deptno;
+--------+----------+
| deptno | count(1) |
+--------+----------+
| 1 | 2 |
| 2 | 1 |
| 4 | 1 |
+--------+----------+
3 rows in set (0.00 sec)

更详细一些,既要统计部门人数,又要统计总人数

mysql> select deptno,count(1) from emp group by deptno with rollup;
+--------+----------+
| deptno | count(1) |
+--------+----------+
| 1 | 2 |
| 2 | 1 |
| 4 | 1 |
| NULL | 4 |
+--------+----------+
4 rows in set (0.00 sec)

统计人数大于 1 的部门

mysql> select deptno,count(1) from emp group by deptno having count(1)>1;
+--------+----------+
| deptno | count(1) |
+--------+----------+
| 1 | 2 |
+--------+----------+
1 row in set (0.00 sec)

统计公司所有员工薪水总额、最高和最低薪水

mysql> select * from emp;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx | 2000-01-01 | 2000.00 | 1 |
| lisa | 2003-02-01 | 4000.00 | 2 |
| bjguan | 2004-04-02 | 5000.00 | 1 |
| dony | 2005-02-05 | 2000.00 | 4 |
+--------+------------+---------+--------+
4 rows in set (0.00 sec) mysql> select sum(sal),max(sal),min(sal) from emp;
+----------+----------+----------+
| sum(sal) | max(sal) | min(sal) |
+----------+----------+----------+
| 13000.00 | 5000.00 | 2000.00 |
+----------+----------+----------+
1 row in set (0.00 sec)

表连接

当需要同时显示多个表中的字段时,就可以用表连接来实现这样的功能。从大类上分,表连接分为内连接和外连接,它们之间的最主要区别是,内连接仅选出两张表中互相匹配的记录,而外连接会选出其他不匹配的记录。常用的是内连接。

查询出所有雇员的名字和所在部门名称,因为雇员名称和部门分别存放在表 emp 和 dept 中,因此,需要使用表连接来进行查询

mysql> select * from emp;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx | 2000-01-01 | 2000.00 | 1 |
| lisa | 2003-02-01 | 4000.00 | 2 |
| bjguan | 2004-04-02 | 5000.00 | 1 |
| dony | 2005-02-05 | 2000.00 | 4 |
+--------+------------+---------+--------+
4 rows in set (0.00 sec) mysql> select * from dept;
+--------+----------+
| deptno | deptname |
+--------+----------+
| 1 | tach |
| 2 | sale |
| 5 | fin |
+--------+----------+
3 rows in set (0.01 sec) mysql> select ename,deptname from emp,dept where emp.deptno=dept.deptno;
+--------+----------+
| ename | deptname |
+--------+----------+
| zzx | tach |
| bjguan | tach |
| lisa | sale |
+--------+----------+
3 rows in set (0.00 sec)

外连接又分为左连接右连接

  • 左连接:包含所有的左边表中的记录甚至是右边表中没有和它匹配的记录。
  • 右连接:包含所有的右边表中的记录甚至是左边表中没有和它匹配的记录。

查询 emp 中所有用户名和所在部门名称

mysql> select * from emp;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx | 2000-01-01 | 2000.00 | 1 |
| lisa | 2003-02-01 | 4000.00 | 2 |
| bjguan | 2004-04-02 | 5000.00 | 1 |
| dony | 2005-02-05 | 2000.00 | 4 |
+--------+------------+---------+--------+
4 rows in set (0.00 sec) mysql> select * from dept;
+--------+----------+
| deptno | deptname |
+--------+----------+
| 1 | tach |
| 2 | sale |
| 5 | fin |
+--------+----------+
3 rows in set (0.00 sec) mysql> select ename,deptname from emp left join dept on emp.deptno=dept.deptno;
+--------+----------+
| ename | deptname |
+--------+----------+
| zzx | tach |
| bjguan | tach |
| lisa | sale |
| dony | NULL |
+--------+----------+
4 rows in set (0.00 sec)

右连接和左连接类似,两者之间可以互相转化,上面的例子可以改写为如下的右连接

mysql> select ename,deptname from dept right join emp on dept.deptno=emp.deptno;
+--------+----------+
| ename | deptname |
+--------+----------+
| zzx | tach |
| bjguan | tach |
| lisa | sale |
| dony | NULL |
+--------+----------+
4 rows in set (0.00 sec)

子查询

某些情况下,当进行查询的时候,需要的条件是另外一个 select 语句的结果,这个时候,就要用到子查询。用于子查询的关键字主要包括 innot in=!=existsnot exists 等。

从 emp 表中查询出所有部门在 dept 表中的所有记录

mysql> select * from emp
-> where deptno
-> in(select deptno from dept);
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx | 2000-01-01 | 2000.00 | 1 |
| bjguan | 2004-04-02 | 5000.00 | 1 |
| lisa | 2003-02-01 | 4000.00 | 2 |
+--------+------------+---------+--------+
3 rows in set (0.00 sec)

如果子查询记录数唯一,还可以用 = 代替 in

mysql> select * from emp
-> where deptno = (select deptno from dept);
ERROR 1242 (21000): Subquery returns more than 1 row
mysql> select * from emp
-> where deptno = (select deptno from dept limit 1);
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx | 2000-01-01 | 2000.00 | 1 |
| bjguan | 2004-04-02 | 5000.00 | 1 |
+--------+------------+---------+--------+
2 rows in set (0.00 sec)

某些情况下,子查询可以转化为表连接

mysql> select * from emp where deptno in(select deptno from dept);
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx | 2000-01-01 | 2000.00 | 1 |
| bjguan | 2004-04-02 | 5000.00 | 1 |
| lisa | 2003-02-01 | 4000.00 | 2 |
+--------+------------+---------+--------+
3 rows in set (0.00 sec) mysql> select emp.* from emp, dept where emp.deptno=dept.deptno;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx | 2000-01-01 | 2000.00 | 1 |
| bjguan | 2004-04-02 | 5000.00 | 1 |
| lisa | 2003-02-01 | 4000.00 | 2 |
+--------+------------+---------+--------+
3 rows in set (0.00 sec)

注意:子查询和表连接之间的转换主要应用在两个方面。

  • MySQL 4.1 以前的版本不支持子查询,需要用表连接来实现子查询的功能.
  • 表连接在很多情况下用于优化子查询。

记录联合

将两个表的数据按照一定的查询条件查询出来后,将结果合并到一起显示出来,这个时候,就需要用 unionunion all 关键字来实现这样的功能

SELECT * FROM t1

UNION | UNION ALL

SELECT * FROM t2

...

UNION | UNION ALL

SELECT * FROM tn;

UNION 和 UNION ALL 的主要区别是 UNION ALL 是把结果集直接合并在一起,而 UNION 是将 UNION ALL 后的结果进行一次 DISTINCT,去除重复记录后的结果。

将 emp 和 dept 表中的部门编号的集合显示出来

mysql> select * from emp;
+--------+------------+---------+--------+
| ename | hiredate | sal | deptno |
+--------+------------+---------+--------+
| zzx | 2000-01-01 | 2000.00 | 1 |
| lisa | 2003-02-01 | 4000.00 | 2 |
| bjguan | 2004-04-02 | 5000.00 | 1 |
| dony | 2005-02-05 | 2000.00 | 4 |
+--------+------------+---------+--------+
4 rows in set (0.00 sec) mysql> select * from dept;
+--------+----------+
| deptno | deptname |
+--------+----------+
| 1 | tach |
| 2 | sale |
| 5 | fin |
+--------+----------+
3 rows in set (0.00 sec) mysql> select deptno from emp
-> union all
-> select deptno from dept;
+--------+
| deptno |
+--------+
| 1 |
| 2 |
| 1 |
| 4 |
| 1 |
| 2 |
| 5 |
+--------+
7 rows in set (0.00 sec)

将结果去掉重复记录后显示如下

mysql> select deptno from emp
-> union
-> select deptno from dept;
+--------+
| deptno |
+--------+
| 1 |
| 2 |
| 4 |
| 5 |
+--------+
4 rows in set (0.00 sec)

DML语句的更多相关文章

  1. jdbc java数据库连接 3)Statement接口之执行DDL和DML语句的简化

    上一章的代码中,可以发现,jdbc执行DDL和DML有几个步骤都是一样的: 1)执行语句开始时,创建驱动注册对象.获取连接的数据库对象.创建Statement对象 // 创建驱动注册对象 Class. ...

  2. 详解MySQL---DDL语句、DML语句与DCL语句

    背景:近几年,开源数据库逐渐流行起来.由于具有免费使用.配置简单.稳定性好.性能优良等优点,开源数据库在中低端应用上占据了很大的市场份额,而 MySQL 正是开源数据库中的杰出代表.MySQL 数据库 ...

  3. 数据库 使用DML语句更改数据

    使用DML语句更改数据 添加新数据: 插入单行语句: Insert into 表名(列名)values(‘值’); 插入多行:insert into 表名(列名,…..) Values(‘值’,’值’ ...

  4. mariadb DML语句及用户授权

    DML(Data Manipulation Language):INSERT, DELETE, UPDATE, SELECT INSERT  [INTO]  tbl_name  [(col1,...) ...

  5. 使用DML语句【weber出品必属精品】

    DML语句包含以下语法: INSERT:往一个表中增加新行 DELETE:从一个表中删除掉现有的行 UPDATE:更改一个表中现有的行 INSERT语句语法:INSERT INTO TABLE(COL ...

  6. c# 数据库编程(通过SqlCommand 执行DML语句)

    原来一直是java,python等语言,最近用c#语言,并编写数据库访问代码.使用了之后,这里总结下,分享下c#如何操作数据库. 在java等其它语言中,有一套标准的api来完成数据库访问,并且一般都 ...

  7. SQL基础-----DML语句

    之前已经介绍过SQL基础之DDL(数据库定义语言)语句,http://www.cnblogs.com/cxq0017/p/6433938.html(这是地址) 这篇文章主要介绍DML语句(数据库操纵语 ...

  8. oracle DML语句

    DML语句 1.  插入数据 创建一个新表 create table new_cust as select * from customers --使用insert语句添加行 /* 确定要插入的行所在的 ...

  9. mysql语句-DML语句

    DML语句 DML是指对数据库中表记录的操作,主要包括数据的增删改查以及更新,下面依次介绍 首先创建一张表:: 表名:emp 字段:ename varchar(20),hiredate date ,s ...

  10. dml语句和ddl语句 区别

    delete from user删除所有记录,属于dml语句,一条记录一条记录删除.事务可以作用在dml语句上的 truncate table user;删除所有记录,属于ddl语句,将表删除,然后重 ...

随机推荐

  1. Image Processing and Analysis_8_Edge Detection:Scale-space and edge detection using anisotropic diffusion——1990

    此主要讨论图像处理与分析.虽然计算机视觉部分的有些内容比如特 征提取等也可以归结到图像分析中来,但鉴于它们与计算机视觉的紧密联系,以 及它们的出处,没有把它们纳入到图像处理与分析中来.同样,这里面也有 ...

  2. 【异常】诡异的mysql错误,Pagehelper插件混乱导致吗

    1 详细的异常信息 Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in ...

  3. linux基础_关机重启注销

    1.关机重启命令 (1)shutdown shutdown -h now:表示立即关机 shutdown -h 1:表示1分钟后关机 shutdown -r  now:立即重启 (2)halt:就是直 ...

  4. C# LINQ(10)

    LINQ 查询 var query = from r in Formula1.GetChampions() where r.Country == "Brazil" orderby ...

  5. RuntimeError: can't start new thread

    明明我只是简单跑了一个数据清洗28W数据的python脚本,不知道怎么就报错如下: too many threads running within your python process The &q ...

  6. Java中的集合Collection、Iterator和Foreach用法(一)

    1.Java集合概述 在编程中,常常需要集中存放多个数据.当然我们可以使用数组来保存多个对象.但数组长度不可变化,一旦在初始化时指定了数组长度,则这个数组长度是不可变的,如果需要保存个数变化的数据,数 ...

  7. javascript内置对象一: Array数组

    在JavaScript中的任何事物,字符串,数组,函数等等都是对象. 理解:浏览器自己封装好的对象,可以直接使用. push   /pʊʃ/  增加 在末尾增加              unshif ...

  8. Luogu P2146 [NOI2015]软件包管理器 树剖

    卸载:把子树清空: 安装:把自己到$1$的链改为$1$ #include<cstdio> #include<iostream> #include<cstring> ...

  9. luogu 1156 垃圾陷阱 动态规划

    Code: #include <bits/stdc++.h> #define N 4004 #define setIO(s) freopen(s".in"," ...

  10. LA 6972 Domination

    6972 Domination Edward is the headmaster of Marjar University. He is enthusiastic about chess and of ...