Solved

Creating a SQL Script (batch) file with multiple create view statements

Posted on 2009-07-16
1
836 Views
Last Modified: 2012-05-07
I want to create a Microsoft SQL script file that creates multiple views in a database, and can be run multiple times without an error.

Is this possible. The code below will work, but it won't run a second time without an error. If I add an existence check I get an error that the create view statement isn't the first in the batch, is there a way around this problem?
create view v1

as 

select top 5 * from Name

go
 

create view v2

as

select top 6 * from Name

go

Open in new window

0
Comment
Question by:purplesoup
1 Comment
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 24869839
put this in front of each call:

if object_id('v1') is not null
drop view v1
go
create view v1
as
select top 5 * from Name
go
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how the fundamental information of how to create a table.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now