1

I am trying to create a table (shown below) for my final year project, but I encountered SQL name conflict error. It seems the words 'User' and 'role' are reserved by the SQL. Is there any way I can resolve the issue, without renaming the words.

CREATE TABLE User
(
    ID INT generated by default as identity PRIMARY KEY,
    username varchar(45) NOT NULL,
    password varchar(255) NOT NULL,
    role varchar(255) NOT NULL
);
0

3 Answers 3

4

Throw square brackets around their name (or any reserved word that you want as your column names).

[User]

or

[Role]

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

Comments

2

Put double quotes around User. In general it never hurts to quote all your identifiers.

2 Comments

I'm not sure quotes work, but square brackets seem to be the norm.
Hi Martin Krämer. Thank you very much I just test it and it works for perfectly.
2

Try this is you are using SQL Server(in MySql it can be done using backticks ``):

CREATE TABLE [User]
(
    ID INT generated by default as identity PRIMARY KEY,
    username varchar(45) NOT NULL,
    password varchar(255) NOT NULL,
    [role] varchar(255) NOT NULL
);

On a side note:- It is not recommended to use reserved keywords for tabe name and column names.

Use some other names like Users and Roles which are not reserved keyword and which have a similar namings.

EDIT:

After looking at your comments it looks like you are using Derby. So you need to use double quotes.

Try this:

CREATE TABLE "User"
(
    ID INT generated by default as identity PRIMARY KEY,
    username varchar(45) NOT NULL,
    password varchar(255) NOT NULL,
    "role" varchar(255) NOT NULL
);

1 Comment

Thanks. I tried the exact command and it throws : Error code 30000, SQL state 42X01: Syntax error: Encountered "[" at line 1, column 14. Line 1, column 1

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.