SQL Server 2008 /2000 difference using as column name a reserved keyword
I could be not more sorry guys - the question was a very wrong one. As spotted by you the error is due to the fact that a colum with that name does not exists. The error and the post is due to a misalignement between a staging server and a production server. But the error has been detected by your answers, so many, many thanks
The following statement:
select [user] from bookings
is putting me in troubles. Please, note, square brackets has been placed around the reserved keyword. As you can see, unhappily a reserved keyword has been chosen for a column name (an user, of course), but in the previous application running in SQL Server 2000 the query was executed without errors.
Unfortunately in SQL Server 2008 - to which application is ported - the behaviour is different, it complains and emits an error. 开发者_开发问答Altering the database table could be an horrible headache because a lot of changes in db and code must be made. There is a way to execute the query keeping the name of the column?
Thanks!
2008 is just like before in that it doesn't want you to use reserved names, but I have not had it throwing an error for it.
CREATE TABLE [dbo].[tblUser](
[userid] [int] IDENTITY(1,1) NOT NULL,
[user] [nchar](10) NOT NULL,
CONSTRAINT [PK_tblUser] PRIMARY KEY CLUSTERED
(
[userid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
followed by
select [user] from tbluser
Generated no error on execution.
What error are you getting. I have just created a bookings table in my copy of SQL2008 and getting no such error with
select [user] from bookings
I also have table named user in a different db and don't have issues
精彩评论