3

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

5
  • 1
    oracle, right? if so, i think NUMBER doesn't need the (4) Commented May 25, 2012 at 8:51
  • 1
    Which database software are you trying to create this table in? What error message do you get? Commented May 25, 2012 at 8:51
  • You've got an extra comma after the last column declaration. You've also put "NUT" instead of "NOT" on the last column too! Commented May 25, 2012 at 8:51
  • oh and NUT is a word for crazy :) (last line) Commented May 25, 2012 at 8:51
  • Also, you appear to have a typo -- "NUT" instead of "NOT" Commented May 25, 2012 at 8:52

4 Answers 4

7

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
Sign up to request clarification or add additional context in comments.

3 Comments

I'm using Oracle Express Edition, can you tell me whats the difference between the one I used and the ones you used?
what is the difference between varchar2 and varchar here
@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.
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
);

Comments

3

Try removing the last comma and change NUT to NULL.

Comments

1

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 
    ) 

1 Comment

error is- right syntax to use near '[password] VARCHAR(16) NOT NULL , first_name VARCHAR(20) NOT NULL , ' at line 4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.