0

I am trying to create a table in my database (hosted with 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

2 Answers 2

4

You forgot to add semicolon ; after use .... ; is used to terminate lines in 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)
);
Sign up to request clarification or add additional context in comments.

3 Comments

@HurkNburkS i think CONSTRAINT u_pk PRIMARY KEY (User_Id) should best fit in your table. PRIMARY KEY are unique indexes.
According to @John Woo, CONSTRAINT u_pk PRIMARY KEY (User_Id) is the best way +1
right okay thanks very much! this worked perfectly.. I found out one of my issues was I was using my user account to enter the sql editor not the DB user.
2

First of all you have to create a blank database 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)
)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.