sql中的now()方法

来源:互联网 发布:名片存储软件 编辑:程序博客网 时间:2024/05/16 16:23

now()是sql自带的方法,用于查询当前时间。

下面的 SQL 创建带有日期时间列 (OrderDate) 的 "Orders" 表:

CREATE TABLE Orders (OrderId int NOT NULL,ProductName varchar(50) NOT NULL,OrderDate datetime NOT NULL DEFAULT NOW(),PRIMARY KEY (OrderId))

请注意,OrderDate 列规定 NOW() 作为默认值。作为结果,当您向表中插入行时,当前日期和时间自动插入列中。

现在,我们希望在 "Orders" 表中插入一条新记录:

INSERT INTO Orders (ProductName) VALUES ('Computer')

"Orders" 表将类似这样:

OrderIdProductNameOrderDate1'Computer'2008-12-29 16:25:46.635
0 0
原创粉丝点击