|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 2:24 AM
Points: 5,235,
Visits: 7,040
|
|
Don Avery (1/3/2011) Actually, I'm right - this query will return 0 rows for both SELECT statements as it will never run - you cannot insert into a table with and Identity PK without specifying the column names on the INSERT query. Actually, you are wrong. The script will run. You don't need to specify column names when inserting into a table with an IDENTITY column.
After reading your reply, I started to doubt, so I copied the script, pasted it in SSMS, changed it to work for SQL Server 2005 - I replaced the single INSERT with three INSERT statements:
INSERT INTO @student VALUES( 'Hardy', 100); INSERT INTO @student VALUES ('Rocky', 98); INSERT INTO @student VALUES ('Panky', 99); I then hit the F5 button to execute, and I got the expected results.
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 11:21 AM
Points: 2,163,
Visits: 2,148
|
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 10:31 PM
Points: 339,
Visits: 950
|
|
Hugo Kornelis (1/3/2011)
After reading your reply, I started to doubt, so I copied the script, pasted it in SSMS, changed it to work for SQL Server 2005
Which is a bit of a problem -- 5% of the respondents said zero, zero. I image that most if not all of them were thinking 2000/2005, where that would be the correct answer. I noticed the syntax, but picked the right answer because I remembered someone pointing out this as a new feature in 2008, if not for that I would have thought it was a trick question and picked zero, zero.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 2:24 AM
Points: 5,235,
Visits: 7,040
|
|
john.moreno (1/3/2011)
Hugo Kornelis (1/3/2011)
After reading your reply, I started to doubt, so I copied the script, pasted it in SSMS, changed it to work for SQL Server 2005Which is a bit of a problem -- 5% of the respondents said zero, zero. I image that most if not all of them were thinking 2000/2005, where that would be the correct answer. I noticed the syntax, but picked the right answer because I remembered someone pointing out this as a new feature in 2008, if not for that I would have thought it was a trick question and picked zero, zero. Though I agree that it would have been better to include the version in the question text, or to use a more backward compatible syntax, I don't thnik this should affect the result of the question much. It's 2011 already; the first CTP for SQL Server 2011 has been out for quite some time already - I think it's safe to assume version 2008 when nothing is mentioned explicitly.
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Tuesday, May 01, 2012 7:21 PM
Points: 83,
Visits: 27
|
|
You are correct - I'm an idiot!
I guess I never tried inserting without column names being explicitly stated, but it does indeed work.
don
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Sunday, July 15, 2012 11:15 AM
Points: 35,
Visits: 71
|
|
Thanks. While working with this type of comma seperated string, first we need to split the string with the help of table valued function. We can pass the comma deliminated string as an argument to the table valued function.
Also thanks for the insert statement provoded.
I never used this mode of insert statement.
Thanks.
Reji PR, Bangalore

|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 2:42 PM
Points: 877,
Visits: 1,158
|
|
rejipr1982 (1/3/2011)
Thanks. While working with this type of comma seperated string, first we need to split the string with the help of table valued function. We can pass the comma deliminated string as an argument to the table valued function. Also thanks for the insert statement provoded. I never used this mode of insert statement.  It's good to know that you learn some thing new.
Thanks
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 2:42 PM
Points: 877,
Visits: 1,158
|
|
Hugo Kornelis (1/3/2011)
john.moreno (1/3/2011)
Hugo Kornelis (1/3/2011)
After reading your reply, I started to doubt, so I copied the script, pasted it in SSMS, changed it to work for SQL Server 2005Which is a bit of a problem -- 5% of the respondents said zero, zero. I image that most if not all of them were thinking 2000/2005, where that would be the correct answer. I noticed the syntax, but picked the right answer because I remembered someone pointing out this as a new feature in 2008, if not for that I would have thought it was a trick question and picked zero, zero. Though I agree that it would have been better to include the version in the question text, or to use a more backward compatible syntax, I don't thnik this should affect the result of the question much. It's 2011 already; the first CTP for SQL Server 2011 has been out for quite some time already - I think it's safe to assume version 2008 when nothing is mentioned explicitly. Thanks Hugo for covering me. I assume SQL 2008 still its better to mention SQL Server version when we post any query, article or QofD. Next time I will take care
Thanks
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Today @ 2:35 AM
Points: 304,
Visits: 169
|
|
Im getting the error while running the query
Server: Msg 8101, Level 16, State 1, Line 7 An explicit value for the identity column in table '@student' can only be specified when a column list is used and IDENTITY_INSERT is ON.
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Today @ 1:52 AM
Points: 9,372,
Visits: 6,469
|
|
|
|
|