March 7, 2013 at 5:59 am
+1
Nice Question ....
March 7, 2013 at 7:09 am
GOOD QUESTION...
NICE EXPLANATION FROM GUYS lOKESH, DANNY...
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
March 7, 2013 at 7:40 am
Nice question... I really learned two points.... 1. with go- how to create stored procedures and functions
2. without go- how to create stroed procedures and functions........:-D
Manik
You cannot get to the top by sitting on your bottom.
March 7, 2013 at 10:03 am
Good Question.... lots of fun to read through... I started saying Dibbiddy Dibbidy Dibbiddy....
March 7, 2013 at 10:11 am
Nothing wrong with the following for step 6 though (and the equivalent for step 4):
USE DBDB;
-- no 'GO' necessary
IF OBJECT_ID('dbo.udfUDF') IS NULL
exec('CREATE FUNCTION dbo.udfUDF(@f int) RETURNS INT AS BEGIN SET @f=1 RETURN @f END;');
In my opinion 'GO' is very overused. It's almost "stick a go in everywhere just in case", particularly in code examples.
For instance in this QOD, all except one 'GO' can be ommitted and the whole script executed in one 'GO' (but two batches(!)):
-- Query #1
USE master;
IF DB_ID('DBDB') IS NOT NULL DROP DATABASE DBDB
-- Query #2
IF DB_ID('DBDB') IS NULL CREATE DATABASE DBDB
go -- this one is necessary otherwise the rest of the script won't compile.
-- Query #3
USE DBDB;
IF OBJECT_ID('dbo.TBTB') IS NULL CREATE Table dbo.TBTB (tb1 int)
-- Query #4
IF OBJECT_ID('dbo.uspUSP') IS NULL
exec('CREATE PROCEDURE dbo.uspUSP AS SET NOCOUNT OFF');
-- Query #5
IF OBJECT_ID('dbo.TYTP') IS NULL CREATE TYPE dbo.TPTP AS TABLE(TYTB int)
-- Query #6
IF OBJECT_ID('dbo.udfUDF') IS NULL
exec('CREATE FUNCTION dbo.udfUDF(@f int) RETURNS INT AS BEGIN SET @f=1 RETURN @f END;');
March 7, 2013 at 3:06 pm
I ran all 6 in my SQL Server 2008R2 and the only one that did not error was the first one. Query 2 gives me error:
Msg 5133, Level 16, State 1, Line 1
Directory lookup for the file "D:\Database files\SQL Server\DBDB.mdf" failed with the operating system error 3(The system cannot find the path specified.).
and this caused every subsequent query to fail. I even changed the query 2 to use DB_ID. I changed back to original which I knew would fail and yes, that fails too.
So what is going on here? I am running SQL Server 2008R2 Express. Could that be it? I am just learning SQL Server. I work mostly with Oracle.
March 7, 2013 at 3:40 pm
Thanks for the question.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
March 7, 2013 at 9:39 pm
I am nominating this for the Most Misguided QotD of the Year Award.
March 8, 2013 at 12:18 am
Revenant (3/7/2013)
I am nominating this for the Most Misguided QotD of the Year Award.
Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
March 8, 2013 at 2:13 am
sgehret 2557 (3/7/2013)
I ran all 6 in my SQL Server 2008R2 and the only one that did not error was the first one. Query 2 gives me error:Msg 5133, Level 16, State 1, Line 1
Directory lookup for the file "D:\Database files\SQL Server\DBDB.mdf" failed with the operating system error 3(The system cannot find the path specified.).
and this caused every subsequent query to fail. I even changed the query 2 to use DB_ID. I changed back to original which I knew would fail and yes, that fails too.
So what is going on here? I am running SQL Server 2008R2 Express. Could that be it? I am just learning SQL Server. I work mostly with Oracle.
sgehret: If the directory doesn't exist, create it. If the directory exists (and there's enough free space on the disk for a new database), start services.msc and see what user the SQL Server service is running under, then look at the permissions on the directory to check the service user has full access.
March 8, 2013 at 4:21 am
Revenant (3/7/2013)
I am nominating this for the Most Misguided QotD of the Year Award.
I think it's a poor fifth in that race.
Tom
March 8, 2013 at 4:45 am
Interesting question, thanks.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
March 8, 2013 at 6:15 am
Interesting question, thanks so much!
March 8, 2013 at 10:11 am
L' Eomot Inversé (3/8/2013)
Revenant (3/7/2013)
I am nominating this for the Most Misguided QotD of the Year Award.I think it's a poor fifth in that race.
Tom,
This being early March, your comment says volumes about the QotD so far this year.
The thing I must say about all those questions is that each has given the community a great platform for discussion about topics and uses that might not have taken place without the poor questions.
M.
Not all gray hairs are Dinosaurs!
March 8, 2013 at 10:20 am
Hi,
It's official. I'm an idiot. I have my local SQL Server setup to create data files on my D drive due to space issues. But I connected to a database on another server to test this question. Big duh! on my part. When I finally figured it out and ran it on my Server and saw the correct results.
Sorry for any inconvenience. Thanks for your information.
Take care,
Scott
Viewing 15 posts - 16 through 30 (of 41 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy