views:

31

answers:

2

Maybe not literally but the query below gets an error near user. If i change it to userZ it works. WHY can i not use that name? Is there a way to specific its a field instead of a keyword? (or whatever it is)

create table Post2 (
id INTEGER PRIMARY KEY NOT NULL,
title nvarchar(max)
 NOT NULL,
body nvarchar(max)
 NOT NULL,
user integer REFERENCES Post1(id));
+3  A: 

Reserved words, like user should be enclosed in brackets.
Take a look at Using Identifiers for a more in depth explanation.

CREATE TABLE Post2 (
  id INTEGER PRIMARY KEY NOT NULL
  , title NVARCHAR(MAX)NOT NULL
  , body NVARCHAR(MAX) NOT NULL
  , [User] INTEGER REFERENCES Post1(id)
);
Lieven
However, it should be pointed out that using reserved words is a poor practice to be avoided not just gotten around.
HLGEM
+2  A: 

USER is a reserved word.

Try delimiting it with "" (e.g. "user" or [user])

Read more on using delimited identifiers here.

Tim Drisdelle