简体   繁体   English

尝试创建表时出现MySQL语法错误

[英]MySql syntax error while trying to create a table

I am trying to create a table in my database (hosted with godaddy) 我正在尝试在数据库中创建一个表(由godaddy托管)

when ever I try to create a table in the database it gives me an error 每当我尝试在数据库中创建表时,都会给我一个错误

#1046 - No database selected 

So I am trying to create a table like this 所以我试图创建一个这样的表

USE orderformuser

CREATE TABLE `users`(
`user_id` int NOT NULL AUTO_INCREMENT,
`username` char(25),
`password` char(40),
UNIQUE (User_Id)
)

However I am getting this error now.. and I just don't know what I am doing wrong 但是我现在遇到这个错误..而我只是不知道我在做什么错

#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 TABLE `users`(
`user_id` int NOT NULL AUTO_INCREMENT,
`username` char(2' at line 3

any help would be appreciated 任何帮助,将不胜感激

You forgot to add semicolon ; 你忘了加分号; after use ... . use ...use ... ; is used to terminate lines in mysql. 用于终止mysql中的行。

USE orderformuser;

CREATE TABLE `users`
(
   `user_id` int NOT NULL AUTO_INCREMENT,
   `username` char(25),
   `password` char(40),
   CONSTRAINT u_pk PRIMARY KEY (User_Id)
);

First of all you have to create a blank database orderformuser. 首先,您必须创建一个空白的数据库orderformuser。 After you have to entry into this database and try to create the table with your code changed because you have forgot ";" 在您必须进入该数据库并尝试创建表之后,由于忘记了“;”而更改了代码; like this: 像这样:

USE orderformuser;
CREATE TABLE `users`
(
`user_id` int NOT NULL AUTO_INCREMENT,
`username` char(25),
`password` char(40),
UNIQUE (User_Id)
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM