May 25, 2013 at 2:43 am
May 27, 2013 at 12:26 am
May 27, 2013 at 2:09 am
Good question, but the answer is wrong.
SQL Server evaluates object references during parse time. Flow-control logic is not applied at this stage.
This is not true. If you change the temporary table to a regular table (e.g. dbo.Tab), the script will work.
DECLARE @MoreColumns bit;
SET @MoreColumns = 1
IF @MoreColumns = 0
CREATE TABLE dbo.Tab (
id int,
name varchar(50)
);
ELSE
BEGIN
CREATE TABLE dbo.Tab (
id int,
name varchar(50),
Description varchar(8000),
nvarchar(200)
)
END
GO
DROP TABLE dbo.Tab
If more than one temporary table is created inside a single stored procedure or batch, they must have different names
ms-help://MS.SQLCC.v10/MS.SQLSVR.v10.en/s10de_6tsql/html/1e068443-b9ea-486a-804f-ce7b6e048e8b.htm
Obviously SQL Server does not care if the two create table statements are mutually exclusive and does not allow that.
Best Regards,
Chris Bรผttner
May 27, 2013 at 3:50 am
1 +
Neeraj Prasad Sharma
Sql Server Tutorials
May 27, 2013 at 4:49 am
If more than one temporary table is created inside a single stored procedure or batch, they must have different names
ms-help://MS.SQLCC.v10/MS.SQLSVR.v10.en/s10de_6tsql/html/1e068443-b9ea-486a-804f-ce7b6e048e8b.htm
Obviously SQL Server does not care if the two create table statements are mutually exclusive and does not allow that.[/quote]
+1 nice question
Manik
You cannot get to the top by sitting on your bottom.
May 28, 2013 at 2:48 am
Danny Ocean (5/24/2013)
I really like this question. It's a very import basic question.Thanks for question. ๐
+1 ๐
MCTS | MCITP | Microsoft SQL Server 2008 Administration & Development
MCSA | MCSE | Business Intelligence SQL Server 2012
May 28, 2013 at 5:36 am
Christian Buettner-167247 (5/27/2013)
Good question, but the answer is wrong.SQL Server evaluates object references during parse time. Flow-control logic is not applied at this stage.
This is not true. If you change the temporary table to a regular table (e.g. dbo.Tab), the script will work.
DECLARE @MoreColumns bit;
SET @MoreColumns = 1
IF @MoreColumns = 0
CREATE TABLE dbo.Tab (
id int,
name varchar(50)
);
ELSE
BEGIN
CREATE TABLE dbo.Tab (
id int,
name varchar(50),
Description varchar(8000),
nvarchar(200)
)
END
GO
DROP TABLE dbo.Tab
If more than one temporary table is created inside a single stored procedure or batch, they must have different names
ms-help://MS.SQLCC.v10/MS.SQLSVR.v10.en/s10de_6tsql/html/1e068443-b9ea-486a-804f-ce7b6e048e8b.htm
Obviously SQL Server does not care if the two create table statements are mutually exclusive and does not allow that.
+1
I think table variable and temp tables will be created at compilation time, so control flow logic will not work here.
can someone pour more light on it?
--
Dineshbabu
Desire to learn new things..
May 28, 2013 at 9:02 am
Interestingly, while the answer does hold for 2005+, for us dinosaurs who still have a few SQL Server 2000 systems, it throws a parse time syntax error on the USER keyword first. Renaming to a different column does still yield the duplicate table name error at parse time, but surprisingly it seems to do the syntax check before catching the "duplicate" table name on my legacy system.
I guess it just goes to show you should always specify version numbers.
May 29, 2013 at 8:19 am
NBSteve (5/28/2013)
Interestingly, while the answer does hold for 2005+, for us dinosaurs who still have a few SQL Server 2000 systems, it throws a parse time syntax error on the USER keyword first. Renaming to a different column does still yield the duplicate table name error at parse time, but surprisingly it seems to do the syntax check before catching the "duplicate" table name on my legacy system.I guess it just goes to show you should always specify version numbers.
I agree. I tried it first in SQL Server 2000 and received "Incorrect syntax near the keyword 'USER'". Then I realized that it must apply to newer versions, and tested the code in 2008 where it gave the duplicate table error. I think it is a very good question, because it shows how significantly versions differ from each other. Thanks!
June 3, 2013 at 1:41 am
Good question. I was able to answer as few days back, I think, someone posted the QOTD on same concept. Revision is good.
June 18, 2013 at 8:18 am
occured to me few weeks ago
thank's for the question
Viewing 11 posts - 16 through 25 (of 25 total)
You must be logged in to reply to this topic. Login to reply