1
votes

I want to create a tb_order database table, but I don't know which code format is wrong.

CREATE TABLE tb_order (
id INT(11) NOT NULL AUTO_INCREMENT,
user_id INT(11) DEFAULT NULL,
order_number VARCHAR(255) DEFAULT NULL,
CREATE DATETIME DEFAULT NULL,
updated DATETIME DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=INNODB AUTO_INCREMENT=2 DEFAULT  
CHARSET=utf8;

Error message displayed

Query : CREATE TABLE tb_order ( id int(11) NOT NULL AUTO_INCREMENT, user_id int(11) DEFAULT NULL, order_number varchar(255) DEFAULT NULL... Error Code : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'create datetime DEFAULT NULL, updated datetime DEFAULT NULL, PRIMARY KEY (id) ) ' at line 5 Execution Time : 00:00:00:000 Transfer Time : 00:00:00:000 Total Time : 00:00:00:000

3
Use created instead of create for a column name. - lurker

3 Answers

6
votes

CREATE is a reserved keyword. Quote it using backticks, or use a different column name.

2
votes

You have used a MySQL keyword as a column name. I have mentioned that in the code. Check that out.

CREATE TABLE tb_order (
id INT(11) NOT NULL AUTO_INCREMENT,
user_id INT(11) DEFAULT NULL,
order_number VARCHAR(255) DEFAULT NULL,
some_other_coloumn_name DATETIME DEFAULT NULL,
updated DATETIME DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=INNODB AUTO_INCREMENT=2 DEFAULT  
CHARSET=utf8;
0
votes

Try This --

please change column name create replace to create_db and also update to update_db

CREATE TABLE `tb_order` (
  `id` int(11) NOT NULL,
  `user_id` int(11) DEFAULT NULL,
  `order_number` varchar(255) DEFAULT NULL,
  `create_db` datetime(6) DEFAULT NULL,
  `updated_db` datetime(6) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `tb_order`
--
ALTER TABLE `tb_order`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `tb_order`
--
ALTER TABLE `tb_order`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;