Reputation:
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)
);
Upvotes: 0
Views: 414
Reputation: 222402
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.
Upvotes: 7