Monday, October 02, 2006

SQL Server Teaser

Here is a quick SQL Server teaser

Create the following table

CREATE TABLE [barney ]
barneyId INT

Then look at the following 4 statements which one will fail?
Do not run the statements try to guess, Is it A, B, C or D (or more than one?)

INSERT [barney ] VALUES (1)

INSERT barney VALUES (1)

INSERT "barney" VALUES (1)

INSERT [barney] VALUES (1)

BTW the idea for this post came after reading "Another reason to hate quoted identifiers..." on Louis Davidson's blog


FreeToDev said...

Im using SQL 2005 and none of them fail for me! 4 inserted rows.

Denis the SQL Menace said...

Yep same here, I ran it on 2000 and 2005

I did expect the last two to fail somehow