uTools-Manuals/docs/sql/MySQL NOW() 函数.html
2019-05-07 10:15:08 +08:00

17 lines
1.8 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>MySQL NOW() 函数</h1>
<h2>定义和用法</h2> <p>NOW() 返回当前的日期和时间。</p> <h3><b>语法</b></h3> <div class="code notranslate"><pre><code class="language-sql"><div> NOW()</div></code></pre></div> <h3>实例</h3> <p>下面是 SELECT 语句:</p> <div class="code notranslate"><pre><code class="language-sql"><div> SELECT NOW(),CURDATE(),CURTIME()</div></code></pre></div> <p>结果如下所示:</p> <table class="reference notranslate">
<tr>
<th align="left" width="34%">NOW()</th> <th align="left" width="33%">CURDATE()</th> <th align="left" width="33%">CURTIME()</th> </tr>
<tr>
<td align="left">2008-11-11 12:45:34</td> <td align="left">2008-11-11</td> <td align="left">12:45:34</td> </tr>
</table>
<h3>实例</h3> <p>下面的 SQL 创建带有日期时间列OrderDate的 "Orders" 表:</p> <div class="code notranslate"><pre><code class="language-sql"><div> CREATE TABLE Orders<br/> (<br/> OrderId int NOT NULL,<br/> ProductName varchar(50) NOT NULL,<br/> OrderDate datetime NOT NULL DEFAULT NOW(),<br/> PRIMARY KEY (OrderId)<br/> )</div></code></pre></div> <p>请注意OrderDate 列规定 NOW() 作为默认值。作为结果,当您向表中插入行时,当前日期和时间自动插入列中。</p> <p>现在,我们想要在 "Orders" 表中插入一条记录:</p> <div class="code notranslate"><pre><code class="language-sql"><div> INSERT INTO Orders (ProductName) VALUES ('Jarlsberg Cheese')</div></code></pre></div> <p>"Orders" 表将如下所示:</p> <table class="reference notranslate">
<tr>
<th align="left">OrderId</th> <th align="left">ProductName</th> <th align="left">OrderDate</th> </tr>
<tr>
<td>1</td> <td>Jarlsberg Cheese</td> <td>2008-11-11 13:23:44.657</td> </tr>
</table>
<div class="text-center padding-10 margin-t-5">
</div>
</div>