添加完成

This commit is contained in:
2021-05-06 14:07:48 +08:00
parent ec6ad569c9
commit 995f1b33c4
8 changed files with 73 additions and 1 deletions

View File

@@ -93,4 +93,76 @@ insert class(name) value("李四");
![图 3](../../images/cf4c2d67f9e61957ecd9e0b15f88708fa1b082c8466fe58e87f47c6fdd77c857.png)
只有名字 其他的都是null
只有名字 其他的都是null只要是不写的字段默认都会是null。
### 可以省略字段名
上面添加的时候都会写上字段名字,但是名字都是可以省略的,只需要遵循语法规范。
```sql
INSERT INTO table VALUE(value1,value2,...);
```
写法是怎么样的呢后面value的顺序需要跟建表时候的字段顺序一样而且数量需要一样的。
例如现在的这个表
```sql
insert into class value('王五','',11);
```
![图 1](../../images/70c8fced863114fc9da9c3bef072a664205ad74208834f4ad211bc0ac11b8907.png)
查询一下
![图 2](../../images/560eaa119c7b2d863f1d67f8e02479bc78590e2df918969ab45fef5bf0db348c.png)
已经出现了
如果说少些了或者多写了会怎么样呢?
```sql
insert into class value('王五','');
```
![图 3](../../images/47825a90e74ed9efc2bfd68edd33ff23fa1a4b83fb51b4293d49753782c84394.png)
```sql
insert into class value('王五','',11,2);
```
![图 4](../../images/43a26e249cb890dcad72ff1ae2f5b6d2510b88c3f3b897ddd2af1a551abd6251.png)
两个错误都是一样的,翻译一下
![图 5](../../images/34180375660480f0888de766b4ef42ed9a39ec72d4c33123101773af694b701e.png)
如果想这么添加必须个数一样,所以一般不会使用这样的添加方法。
### 一次添加多条数据
现在每次执行一行的时候都是添加的一条数据,有时候我们需要同时添加多条数据的时候怎么办呢?
```sql
INSERT INTO table VALUES(value1,value2,...),(value1,value2,...),(value1,value2,...),....;
```
使用上面的语法就可以比如我们现在的这个class表。
```sql
insert into class(name,sex,age) values('小红','',11),('小名','',11),('小白','',11);
```
这样一次我们添加三条数据,可以再往后添加更多的数据。
![图 6](../../images/269762a748666237f4c75c4e78526b32c2dff37db2346aea3757933f4ecc8f3d.png)
添加成功了,查询一下
![图 7](../../images/007b78cc30be892d485e497caa3bbb1f0203ec1cbeda4ab9378408cc018ce9a8.png)
下面添加的那三个已经成功添加进去了。
## 结束
插入数据已经说完了,下面就是修改数据和删除数据了。

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB