0

Can someone help me find the reason this SQL query isn't working in Microsoft SQL Server?

CREATE TABLE USER 
(
     USER_ID int NOT NULL PRIMARY KEY,
     USER_L_NAME varchar(30) NOT NULL,
     USER_F_NAME varchar(20) NOT NULL,
     PASSWORD varchar(20) NOT NULL,
     USERNAME varchar(20) NOT NULL,
     DOB date NOT NULL,
     COUNTRY char(30) NOT NULL,
     STATE_REGION char(2),
     EMAIL varchar(20) NOT NULL,
     STREET varchar(50) NOT NULL,
     CITY varchar(30),
     ZIP_CODE char(5),
     MOBILE_PHONE char(11)
);
4
  • 3
    What does it means "isn't working"? What error are you getting? Commented Nov 12, 2020 at 22:35
  • @Alejandro general syntax error Commented Nov 12, 2020 at 22:38
  • 2
    @JustinLowenstein When you report an error, please don't paraphrase. Cut & paste the entire message. Commented Nov 12, 2020 at 22:40
  • We should NEVER store plain-text passwords in a database. Commented Nov 13, 2020 at 13:45

1 Answer 1

7

USER is a reserved word in SQL Server - as in most other databases.

You can either quote this identifier by surrounding it with square brackets (CREATE TABLE [USER] (...)), or change the table name to something else - such as USERS for example.

I would recommend the latter. Using reserved words for identifiers is error-prone (you need to quote the identifier everywhere you use it later on), and can easily be avoided.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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