文章目录
在上一小节中介绍了 MySQL 数据库的一些最最最基础的入门级也是必须要掌握的10条语句,本节将继续深入学习 MySQL 的增删改查语句。本节讲的增删改查是相对于 表而言的。
1、准备工作
想要对表进行增删改查,首先应该有张表,假设我们要统计大学同学工作之后的工作情况,建立了如下表格:
姓名 | 性别 | 公司 | 工资 |
---|---|---|---|
准备工作:
mysql> create database salarydb;
Query OK, 1 row affected (0.01 sec)
mysql> use salarydb;
Database changed
mysql> create table class(
-> id int primary key auto_increment,
-> name varchar(10) not null default '',
-> gender char(1) not null default '',
-> company varchar(20) not null default '',
-> salary decimal(6,2) not null default 0.00
-> )engine myisam charset utf8;
Query OK, 0 rows affected, 1 warning (0.04 sec)
mysql> show tables;
+--------------------+
| Tables_in_salarydb |
+--------------------+
| class |
+--------------------+
1 row in set (0.00 sec)
mysql> desc class;
+---------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(10) | NO | | | |
| gender | char(1) | NO | | | |
| company | varchar(20) | NO | | | |
| salary | decimal(6,2) | NO | | 0.00 | |
+---------+--------------+------+-----+---------+----------------+
5 rows in