Solved

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

Posted on 2009-07-16
1
835 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

744 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

9 Experts available now in Live!

Get 1:1 Help Now