SQL Clone
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 (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: Administrators
Points: 12617 Visits: 16
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
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1611 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 Guru
SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)

Group: General Forum Members
Points: 220331 Visits: 46279

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
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1611 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-Addicted
SSC-Addicted (400 reputation)SSC-Addicted (400 reputation)SSC-Addicted (400 reputation)SSC-Addicted (400 reputation)SSC-Addicted (400 reputation)SSC-Addicted (400 reputation)SSC-Addicted (400 reputation)SSC-Addicted (400 reputation)

Group: General Forum Members
Points: 400 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
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2109 Visits: 210
I was hoping for the synthax [sic] error, never seen one of those before
Red8Rain
Red8Rain
Right there with Babe
Right there with Babe (734 reputation)Right there with Babe (734 reputation)Right there with Babe (734 reputation)Right there with Babe (734 reputation)Right there with Babe (734 reputation)Right there with Babe (734 reputation)Right there with Babe (734 reputation)Right there with Babe (734 reputation)

Group: General Forum Members
Points: 734 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
SSCertifiable
SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)

Group: General Forum Members
Points: 7788 Visits: 4000
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 (533 reputation)Mr or Mrs. 500 (533 reputation)Mr or Mrs. 500 (533 reputation)Mr or Mrs. 500 (533 reputation)Mr or Mrs. 500 (533 reputation)Mr or Mrs. 500 (533 reputation)Mr or Mrs. 500 (533 reputation)Mr or Mrs. 500 (533 reputation)

Group: General Forum Members
Points: 533 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 Guru
SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)

Group: General Forum Members
Points: 220331 Visits: 46279

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