What is the syntax error in Create table statement?

10,621

Solution 1

Do this

create table Users (
    user_id numeric(4) PRIMARY KEY ,
    username VARCHAR(16) NOT NULL,
    password VARCHAR(16) NOT NULL,
    first_name VARCHAR(20) NOT NULL,
    last_name VARCHAR(20) NOT NULL
);

I Changed:

  • number to numeric
  • removed last comma
  • varchar2 to varchar
  • NUT to NOT

Solution 2

Try removing the last comma and change NUT to NULL.

Solution 3

Try

create table Users (
    user_id NUMBER PRIMARY KEY ,
    username VARCHAR2(16) NOT NULL,
    password VARCHAR2(16) NOT NULL,
    first_name VARCHAR2(20) NOT NULL,
    last_name VARCHAR2(20) NOT NULL
);

Solution 4

Im assuming this is for SQL SERVER?

   CREATE TABLE Users ( 
        user_id INT PRIMARY KEY 
    ,   username VARCHAR(16) NOT NULL
    ,   [password] VARCHAR(16) NOT NULL
    ,   first_name VARCHAR(20) NOT NULL
    ,   last_name VARCHAR(20) NOT NULL 
    ) 
Share:
10,621
Ali Bassam
Author by

Ali Bassam

Peaceful Lebanese Citizen, Loves Computers and Technology, Programming and the Web. You can follow me here alibassam.com here twitter.com/alibassam_ and here.. on StackOverflow!

Updated on June 25, 2022

Comments

  • Ali Bassam
    Ali Bassam almost 2 years

    I'm sorry if this is too easy, but I'm tired and cannot seem to solve this on my own. Can anyone see what is wrong with this command?

    create table Users (
       user_id NUMBER(4) PRIMARY KEY ,
       username VARCHAR2(16) NOT NULL,
       password VARCHAR2(16) NOT NULL,
       first_name VARCHAR2(20) NOT NULL,
       last_name VARCHAR2(20) NUT NULL,
    );
    

    Edit: Thanks all. Problem solved. It was the last comma and the NUT :P

  • Ali Bassam
    Ali Bassam about 12 years
    I'm using Oracle Express Edition, can you tell me whats the difference between the one I used and the ones you used?
  • Javascript Coder
    Javascript Coder about 12 years
    error is- right syntax to use near '[password] VARCHAR(16) NOT NULL , first_name VARCHAR(20) NOT NULL , ' at line 4
  • Javascript Coder
    Javascript Coder about 12 years
    what is the difference between varchar2 and varchar here
  • juergen d
    juergen d about 12 years
    @AliBassam: Here is an overview. You can use your data types. You did not specify which DB engine you are using and NUMBER and VARCHAR2 are not available on all DB Engines. Since you are using Oracle these types are fine too.