Home > Archive > MS SQL Server > March 2006 > How to create schem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to create schem
hanklvr@yahoo.com

2006-03-24, 7:26 am

Hello all,

I've always tried to write my SQL script so that they could run
multiple times without error so when I was creating a new schema i get
an error

USE AdventureWorks
GO
IF NOT EXISTS(SELECT * FROM sys.schemas where [name] = 'temp')
CREATE SCHEMA temp AUTHORIZATION dbo
--END IF
GO

this code works
USE AdventureWorks
GO
IF NOT EXISTS(SELECT * FROM sys.schemas where [name] = 'temp')
PRINT 'CREATE SCHEMA temp AUTHORIZATION dbo'
--END IF
GO

and this code works
USE AdventureWorks
GO

CREATE SCHEMA temp AUTHORIZATION dbo
GO

can anyone shed some light on this.

Thanks in advance for your help.

Regards,
HJ

Sue Hoegemeier

2006-03-26, 8:23 pm

Try something like:
USE AdventureWorks
GO
IF NOT EXISTS(SELECT * FROM sys.schemas where [name] =
'temp')
EXEC('CREATE SCHEMA temp AUTHORIZATION dbo')

-Sue

On 23 Mar 2006 09:26:13 -0800, hanklvr@yahoo.com wrote:

>Hello all,
>
>I've always tried to write my SQL script so that they could run
>multiple times without error so when I was creating a new schema i get
>an error
>
>USE AdventureWorks
>GO
>IF NOT EXISTS(SELECT * FROM sys.schemas where [name] = 'temp')
> CREATE SCHEMA temp AUTHORIZATION dbo
>--END IF
>GO
>
>this code works
>USE AdventureWorks
>GO
>IF NOT EXISTS(SELECT * FROM sys.schemas where [name] = 'temp')
> PRINT 'CREATE SCHEMA temp AUTHORIZATION dbo'
>--END IF
>GO
>
>and this code works
>USE AdventureWorks
>GO
>
>CREATE SCHEMA temp AUTHORIZATION dbo
>GO
>
>can anyone shed some light on this.
>
>Thanks in advance for your help.
>
>Regards,
>HJ


Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2009 droptable.com