Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Question of the Day for 22 Mar 2006


Question of the Day for 22 Mar 2006

Author
Message
Site Owners
Site Owners
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10093 Visits: 1
Comments posted to this topic are about the Question of the Day for 22 Mar 2006 posted at http://www.sqlservercentral.com/testcenter/qod.asp?QuestionID=735.
David le Quesne
David le Quesne
SSC Eights!
SSC Eights! (819 reputation)SSC Eights! (819 reputation)SSC Eights! (819 reputation)SSC Eights! (819 reputation)SSC Eights! (819 reputation)SSC Eights! (819 reputation)SSC Eights! (819 reputation)SSC Eights! (819 reputation)

Group: General Forum Members
Points: 819 Visits: 32

Knowing nothing about how schemas in SQL 2K, I guessed you would get a syntax error, wrongly as it turned out. But when I tried the script, it turned out that answer C. seems to be right after all, I get the error

Server: Msg 195, Level 15, State 10, Line 1
'SCHEMA_NAME' is not a recognized function name.

Is SCHEMA_NAME a SQL Server 2005 function?


David



If it ain't broke, don't fix it...
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47261 Visits: 44392

Category : SQL Server 2005 - TSQL
Question - Worth 2 Point(s):
What will be the result of the last SELECT statement if you execute the T-SQL script below as a sysadmin.

Question category was SQL 2005. There's no such thing as schemas in SQL 2000




Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


David le Quesne
David le Quesne
SSC Eights!
SSC Eights! (819 reputation)SSC Eights! (819 reputation)SSC Eights! (819 reputation)SSC Eights! (819 reputation)SSC Eights! (819 reputation)SSC Eights! (819 reputation)SSC Eights! (819 reputation)SSC Eights! (819 reputation)

Group: General Forum Members
Points: 819 Visits: 32

There are schemas in a limited form in SQL Server 2000. Seem to be a way to create objects and grant permissions in a single logical transaction...

BOL says

"CREATE SCHEMA provides a way to create tables and views and to grant permissions for objects with a single statement. If errors occur when creating any objects or granting any permissions specified in a CREATE SCHEMA statement, none of the objects are created.

The created objects do not have to appear in logical order, except for views that reference other views. For example, a GRANT statement can grant permission for an object before the object itself is created, or a CREATE VIEW statement can appear before the CREATE TABLE statements creating the tables referenced by the view. Also, CREATE TABLE statements can declare foreign keys to tables specified later. The exception is that if the select from one view references another view, the referenced view must be specified before the view that references it."

When I tried the script in SQL Server 2000 everything worked up to the point where I tried to create the second table.

David



If it ain't broke, don't fix it...
Mike Kendall
Mike Kendall
SSC Veteran
SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)SSC Veteran (272 reputation)

Group: General Forum Members
Points: 272 Visits: 45

Using 2005, I received the following message.

SELECT SCHEMA_NAME(schema_id), name FROM sys.objects

WHERE name = 'Table1'

Msg 195, Level 15, State 10, Line 1

'SCHEMA_NAME' is not a recognized function name.

Originally, I had expected an invalid object message ( sys.objects ), and that' just what I got when I tried.

SELECT name FROM sys.objects

WHERE name = 'Table1'

Msg 208, Level 16, State 1, Line 1

Invalid object name 'sys.objects'.


Richard Sisk
Richard Sisk
SSCommitted
SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)

Group: General Forum Members
Points: 1989 Visits: 210
I was hoping for the synthax [sic] error, never seen one of those before
Red8Rain
Red8Rain
SSC-Enthusiastic
SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)

Group: General Forum Members
Points: 168 Visits: 372

I selected A as the answer:

1 (A).

Schema1    Table1dbo        Table1
My coworker suggested B as the answer but I know he was wrong.
Having read and reviewed scheme, it was all good. Then I saw
Answer C, that almost seem right to me because I haven't encounter
sys.objects before and just last night, I got the information I want
from sysobjects ... I was sooo leaning towards C but select B to claim my coworker down.
What do you know, my answer was right.  He was still questioning the concept so we ran the code
in sql 2005 and boom, A, was the correct answer.


-----------------------------
www.cbtr.net
.: SQL Backup Admin Tool :.
webrunner
webrunner
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3031 Visits: 3755
The synthax error seemed to me to be an archaic form of SQL error, perhaps dating from the Middle Ages. I imagine a difference in the SQL keywords, too:

SELECTETH *
FROMME TableTheFirst
ORDERETH BY ColumnTheFirst

:-)

-------------------
"I love spending twice as long and working twice as hard to get half as much done!" – Nobody ever.
Ref.: http://www.adminarsenal.com/admin-arsenal-blog/powershell-how-to-write-your-first-powershell-script

"Operator! Give me the number for 911!" - Homer Simpson

"A SQL query walks into a bar and sees two tables. He walks up to them and says 'Can I join you?'"
Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html
talltop
talltop
Mr or Mrs. 500
Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)

Group: General Forum Members
Points: 507 Visits: 1
The correct answer to this question all depends on what version of SQL Server you are using. SCHEMA_NAME() is only a recognized function in SQL Server 2005, not in SQL Server 2000 and since the version is not stated in the question there are 2 different answers to this misleading question..



GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47261 Visits: 44392

The question does state the version. Look at the category

Category : SQL Server 2005 - TSQL




Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search