#**SQL INSERT INTO 语句**
---
INSERT INTO 语句被用来在表中插入一条新的语句
---
### **The SQL INSERT INTO 语句**
INSERT INTO 语句被用来在表中插入一条新的语句
#### **SQL INSERT INTO Syntax**
INSERT INTO 语句有两种形式.
第一种形式不指定列名,仅仅指定值
---
>INSERT INTO table_name
VALUES (value1,value2,value3,...);
---
第二种形式同时指定列名和值
---
>INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);
---
### **数据表实例**
在本教程中我们将使用周所周知的Northwind 数据库
一下是一部分客户表数据
|**CustomerID**|**CustomerName**|**ContactName**|**Address**|**City**|**PostalCode**|**Country**|
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|1|Alfreds Futterkiste|Maria Anders|Obere Str. 57|Berlin|12209|Germany|
|2|Ana Trujillo Emparedados y helados|Ana Trujillo|Avda. de la Constitución 2222|México D.F.|05021|Mexico|
|3|Antonio Moreno Taquería|Antonio Moreno|Mataderos 2312|México D.F.|05023|Mexico|
|4|Around the Horn|Thomas Hardy|120 Hanover Sq.|London|WA1 1DP|UK|
|5|Berglunds snabbköp|Christina Berglund|Berguvsvägen 8|Luleå|S-958 22|Sweden|
---
### INSERT INTO 应用示例
假设我们想在 "Customers" 表中插入新的一行
我们可以使用下面的这条SQL语句
>示例
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal','Tom B. Erichsen','Skagen 21','Stavanger','4006','Norway');
---
[亲自试一下»](http://w3schools.bootcss.com/sql/trysql_insert_colname.html?filename=trysql_insert_colname)
"Customers" 将变成这个样子
|**CustomerID**|**CustomerName**|**ContactName**|**Address**|**City**|**PostalCode**|**Country**|
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|1|Alfreds Futterkiste|Maria Anders|Obere Str. 57|Berlin|12209|Germany|
|2|Ana Trujillo Emparedados y helados|Ana Trujillo|Avda. de la Constitución 2222|México D.F.|05021|Mexico|
|3|Antonio Moreno Taquería|Antonio Moreno|Mataderos 2312|México D.F.|05023|Mexico|
|4|Around the Horn|Thomas Hardy|120 Hanover Sq.|London|WA1 1DP|UK|
|5|Berglunds snabbköp|Christina Berglund|Berguvsvägen 8|Luleå|S-958 22|Sweden|
---
---
**你注意到我们并没有插入任何数字在CustomerID 这一列中吗?**
CustomerID 随着表中每新增一行数据自动更新一个唯一的值
---
### **在指定的列插入数据**
也可以仅插入特定列的数据
以下这条SQL 语句新增一条数据的时候仅仅插入 "CustomerName", "City", and "Country" 列
>示例
INSERT INTO Customers (CustomerName, City, Country)
VALUES ('Cardinal', 'Stavanger', 'Norway');
[亲自试一下»](http://w3schools.bootcss.com/sql/trysql_insert_cols.html?filename=trysql_insert_cols)
<br>
<br>
<br>
<br>
<br>
- sql文档
- sql简介
- sql语法
- select
- distinct
- where
- and & or
- order by
- insert into
- update
- delete
- injection
- select top
- like
- wildcards
- in
- between
- aliases
- joins
- inner join
- left join
- union
- select into
- insert into select
- create db
- create table
- constraints
- not null
- unique
- primary key
- foreign key
- check
- sql default
- create index
- create index
- drop
- alter
- auto increament
- views
- dates
- null values
- null functions
- data types
- db data types
- SQL Functions
- avg
- count
- first
- last
- max
- min
- sum
- group by
- having
- mid
- len
- round
- now
- format
- quick ref
- hosting
- sql quiz