Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
时间: 2024-02-02 15:09:48 浏览: 46
在MySQL中,当你在表结构中定义了多个TIMESTAMP类型的列,并且这些列的DEFAULT或者ON UPDATE子句中都包含了CURRENT_TIMESTAMP时,就会出现"Error Code : 1293 Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause"错误。
解决这个问题的方法是,确保在表结构中只有一个TIMESTAMP类型的列包含了CURRENT_TIMESTAMP。如果你需要多个TIMESTAMP类型的列,你可以将其他列的DEFAULT或者ON UPDATE子句设置为NULL或者其他合适的值。
以下是一个示例,演示了如何解决这个错误:
```sql
CREATE TABLE my_table (
id INT PRIMARY KEY,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
);
```
在上面的示例中,我们定义了两个TIMESTAMP类型的列:created_at和updated_at。created_at列的DEFAULT子句包含了CURRENT_TIMESTAMP,而updated_at列的DEFAULT子句设置为NULL,并且ON UPDATE子句包含了CURRENT_TIMESTAMP。这样就避免了"Error Code : 1293"错误。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)