|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 8:45 AM
Points: 969,
Visits: 649
|
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Today @ 1:01 PM
Points: 9,367,
Visits: 6,463
|
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 11:51 AM
Points: 5,232,
Visits: 7,023
|
|
da-zero (10/18/2010) Very nice question, definately learned something today. Got it wrong, because the BOL page about CREATE SCHEMA didn't mention anything about batches. Ah well... It doesn't really stand out, but the information is there:
This statement must be executed as a separate batch. (See http://msdn.microsoft.com/en-us/library/ms189462.aspx)
Nice question, Richard - I almost fell for it; I was saved by the feeling of "it can't be that simple, let's look a bit further". (That being said, I always forget which statements must run in seperate batches, so I very often get errors because of that).
Oh, one final remark - if I should copy and paste your script in SSMS and execute it, I would actually get a different error: "Could not locate entry in sysdatabases for database 'TempDB'. No entry found with that name. Make sure that the name is entered correctly." On a server with a case sensitive collation, database names are case sensitive as well. You should use all lower case for the system databases tempdb, system, model, and msdb.
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 8:45 AM
Points: 969,
Visits: 649
|
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 8:03 AM
Points: 770,
Visits: 681
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Wednesday, May 08, 2013 6:16 AM
Points: 2,862,
Visits: 2,464
|
|
Great question. Had to reread to catch the problem because I knew that nobody would intentionally create user objects in tempdb.
Hugo brings up a good point as well about the collation settings applying to the database names. I do not have that collation set so I did not get the same error when running (after answering )
Steve Jimmo Sr DBA “If we ever forget that we are One Nation Under God, then we will be a Nation gone under." - Ronald Reagan
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 11:53 AM
Points: 2,672,
Visits: 2,416
|
|
| Learned something new today, thanks.
|
|
|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 11:30 AM
Points: 1,495,
Visits: 1,507
|
|
Thanks for the question. Very instructive topic and discussion.
I'm a little confused by the wording of the question though.
"What do you anticipate the outcome of the following T-SQL code to be?"
How could this be answered incorrectly? If you mark the answer you did in fact anticipate, shouldn't it be correct? 
Dave
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Wednesday, May 01, 2013 4:52 PM
Points: 1,379,
Visits: 2,626
|
|
Hugo Kornelis (10/18/2010) [quote]
...Oh, one final remark - if I should copy and paste your script in SSMS and execute it, I would actually get a different error: "Could not locate entry in sysdatabases for database 'TempDB'. No entry found with that name. Make sure that the name is entered correctly." On a server with a case sensitive collation, database names are case sensitive as well. You should use all lower case for the system databases tempdb, system, model, and msdb.
Thanks Hugo, This is something that I didn't know.
--------------------------------------------------------------------- Use Full Links: KB Article from Microsoft on how to ask a question on a Forum
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Thursday, May 16, 2013 1:46 PM
Points: 18,732,
Visits: 12,329
|
|
|
|
|