uTools-Manuals/docs/sql/INSERT INTO 语句.html
2019-05-07 10:15:08 +08:00

59 lines
5.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<div class="m-bg">
<h1>SQL INSERT INTO 语句</h1>
<p class="intro">INSERT INTO 语句用于向表中插入新记录。</p> <h2>SQL INSERT INTO 语句</h2> <p>INSERT INTO 语句用于向表中插入新记录。</p> <h3>SQL INSERT INTO 语法</h3> <p>INSERT INTO 语句可以有两种编写形式。</p> <p>第一种形式无需指定要插入数据的列名,只需提供被插入的值即可:</p> <div class="code notranslate"><pre><code class="language-sql"><div> INSERT INTO <em>table_name</em><br/> VALUES (<em>value1</em>,<em>value2</em>,<em>value3</em>,...);</div></code></pre></div> <p>第二种形式需要指定列名及被插入的值:</p> <div class="code notranslate"><pre><code class="language-sql"><div> INSERT INTO <em>table_name</em> (<em>column1</em>,<em>column2</em>,<em>column3</em>,...)<br/> VALUES (<em>value1</em>,<em>value2</em>,<em>value3</em>,...);</div></code></pre></div> <h2>演示数据库</h2> <p>在本教程中,我们将使用众所周知的 Northwind 样本数据库。</p> <p>下面是选自 "Customers" 表的数据:</p> <table class="reference notranslate">
<tr>
<th>CustomerID</th> <th>CustomerName</th> <th>ContactName</th> <th>Address</th> <th>City</th> <th>PostalCode</th> <th>Country</th> </tr>
<tr>
<td>87</td> <td>Wartian Herkku</td> <td>Pirkko Koskitalo</td> <td>Torikatu 38</td> <td>Oulu</td> <td>90110</td> <td>Finland</td> </tr>
<tr>
<td>88</td> <td>Wellington Importadora</td> <td>Paula Parente</td> <td>Rua do Mercado, 12</td> <td>Resende</td> <td>08737-363</td> <td>Brazil</td> </tr>
<tr>
<td>89</td> <td>White Clover Markets</td> <td>Karl Jablonski</td> <td>305 - 14th Ave. S. Suite 3B</td> <td>Seattle</td> <td>98128</td> <td>USA</td> </tr>
<tr>
<td>90<br/><br/>
</td> <td>Wilman Kala</td> <td>Matti Karttunen</td> <td>Keskuskatu 45</td> <td>Helsinki</td> <td>21240</td> <td>Finland</td> </tr>
<tr>
<td>91<br/><br/>
</td> <td>Wolski</td> <td>Zbyszek</td> <td>ul. Filtrowa 68</td> <td>Walla</td> <td>01-012</td> <td>Poland</td> </tr>
</table>
<h2>INSERT INTO 实例</h2> <p>假设我们要向 "Customers" 表中插入一个新行。</p> <p>我们可以使用下面的 SQL 语句:</p> <div class="example margin-b-10"> <h2 class="example">实例</h2> <pre><code class="language-sql"><div class="example_code notranslate"> INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)<br/> VALUES ('Cardinal','Tom B. Erichsen','Skagen 21','Stavanger','4006','Norway'); </div></code></pre> </div> <p>现在,选自 "Customers" 表的数据如下所示:</p> <table class="reference notranslate">
<tr>
<th>CustomerID</th> <th>CustomerName</th> <th>ContactName</th> <th>Address</th> <th>City</th> <th>PostalCode</th> <th>Country</th> </tr>
<tr>
<td>87</td> <td>Wartian Herkku</td> <td>Pirkko Koskitalo</td> <td>Torikatu 38</td> <td>Oulu</td> <td>90110</td> <td>Finland</td> </tr>
<tr>
<td>88</td> <td>Wellington Importadora</td> <td>Paula Parente</td> <td>Rua do Mercado, 12</td> <td>Resende</td> <td>08737-363</td> <td>Brazil</td> </tr>
<tr>
<td>89</td> <td>White Clover Markets</td> <td>Karl Jablonski</td> <td>305 - 14th Ave. S. Suite 3B</td> <td>Seattle</td> <td>98128</td> <td>USA</td> </tr>
<tr>
<td>90<br/><br/>
</td> <td>Wilman Kala</td> <td>Matti Karttunen</td> <td>Keskuskatu 45</td> <td>Helsinki</td> <td>21240</td> <td>Finland</td> </tr>
<tr>
<td>91<br/><br/>
</td> <td>Wolski</td> <td>Zbyszek</td> <td>ul. Filtrowa 68</td> <td>Walla</td> <td>01-012</td> <td>Poland</td> </tr>
<tr>
<td>92</td> <td>Cardinal</td> <td>Tom B. Erichsen</td> <td>Skagen 21</td> <td>Stavanger</td> <td>4006</td> <td>Norway</td> </tr>
</table>
<br/><table class="lamp"><tr>
<th width="34"><span aria-hidden="true" class="g-bg glyphicon glyphicon-flag margin-l-5"></span></th> <td> <strong>您是否注意到,我们没有向 CustomerID 字段插入任何数字?</strong><br/>CustomerID 列是自动更新的,表中的每条记录都有一个唯一的数字。</td> </tr></table>
<h2>在指定的列插入数据</h2> <p>我们也可以在指定的列插入数据。</p> <p>下面的 SQL 语句将插入一个新行,但是只在 "CustomerName"、"City" 和 "Country" 列插入数据CustomerID 字段会自动更新):</p> <div class="example margin-b-10"> <h2 class="example">实例</h2> <pre><code class="language-sql"><div class="example_code notranslate"> INSERT INTO Customers (CustomerName, City, Country)<br/> VALUES ('Cardinal', 'Stavanger', 'Norway'); </div></code></pre> </div> <p>现在,选自 "Customers" 表的数据如下所示:</p> <table class="reference notranslate">
<tr>
<th>CustomerID</th> <th>CustomerName</th> <th>ContactName</th> <th>Address</th> <th>City</th> <th>PostalCode</th> <th>Country</th> </tr>
<tr>
<td>87</td> <td>Wartian Herkku</td> <td>Pirkko Koskitalo</td> <td>Torikatu 38</td> <td>Oulu</td> <td>90110</td> <td>Finland</td> </tr>
<tr>
<td>88</td> <td>Wellington Importadora</td> <td>Paula Parente</td> <td>Rua do Mercado, 12</td> <td>Resende</td> <td>08737-363</td> <td>Brazil</td> </tr>
<tr>
<td>89</td> <td>White Clover Markets</td> <td>Karl Jablonski</td> <td>305 - 14th Ave. S. Suite 3B</td> <td>Seattle</td> <td>98128</td> <td>USA</td> </tr>
<tr>
<td>90<br/><br/>
</td> <td>Wilman Kala</td> <td>Matti Karttunen</td> <td>Keskuskatu 45</td> <td>Helsinki</td> <td>21240</td> <td>Finland</td> </tr>
<tr>
<td>91<br/><br/>
</td> <td>Wolski</td> <td>Zbyszek</td> <td>ul. Filtrowa 68</td> <td>Walla</td> <td>01-012</td> <td>Poland</td> </tr>
<tr>
<td>92</td> <td>Cardinal</td> <td>null</td> <td>null </td> <td>Stavanger</td> <td>null</td> <td>Norway</td> </tr>
</table>
<br/><br/><div class="text-center padding-10 margin-t-5">
</div>
</div>