朱岩希 15:45:05 create table p_information( p_order_number char(10) NOT NULL PRIMARY KEY, b_number char(10) not NULL, b_category char(20) not NULL, s_number char(10) references s_information(s_number), b_purchase_quantity int NOT NULL, p_date date default (getdate()), foreign key (s_number) references s_information(s_number) ); 朱岩希 15:45:10 Error Code: 3770. Default value expression of column 'p_date' contains a disallowed function: `getdate`.有什么错误
时间: 2024-02-11 19:04:00 浏览: 150
CreateTable.rar_create table ja_createTab_createTable
这个错误是因为在 MySQL 中,`getdate()`不是一个合法的默认值表达式。要获取当前日期,可以使用`CURRENT_DATE`或`CURRENT_TIMESTAMP`函数。因此,修改`p_date`列的默认值表达式为`DEFAULT CURRENT_DATE`或`DEFAULT CURRENT_TIMESTAMP`即可。修改后的 SQL 代码如下所示:
```
CREATE TABLE p_information (
p_order_number CHAR(10) NOT NULL PRIMARY KEY,
b_number CHAR(10) NOT NULL,
b_category CHAR(20) NOT NULL,
s_number CHAR(10) REFERENCES s_information(s_number),
b_purchase_quantity INT NOT NULL,
p_date DATE DEFAULT CURRENT_DATE,
FOREIGN KEY (s_number) REFERENCES s_information(s_number)
);
```
阅读全文