Solved

MS SQL creatin a view

Posted on 2011-03-08
3
456 Views
Last Modified: 2012-05-11
I am creating a view that must be updated several times during the month. Right now I have 3 SQL queries to accomplish this.

1st Query    DROP VIEW  {view name}
 2nd            CREATE VIEW (view name) as
                   SELECT  (Several Columns)

3rd             Exec {database name}_grant_permissions
 -------------------------------------------------------------------------------------
How would I combine into 1 SQL Query to run
0
Comment
Question by:fbhunt
3 Comments
 
LVL 15

Assisted Solution

by:derekkromm
derekkromm earned 30 total points
ID: 35069222
well, you can combine the drop/create by doing

alter view <viewname> as
select <...>

the exec would have to be separate

unless you want to put it all in a stored procedure, then you could just put all 3 statements inside it and execute it with "exec sp_Your_Proc"
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 65 total points
ID: 35069241
if the grant permissions is just to regrant the permissions on the view because it had been dropped, do indeed the ALTER VIEW instead, it will retain the permissions
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 30 total points
ID: 35069246
>>I am creating a view that must be updated several times during the month. <<
Which of course begs the question as to why you are doing this.  This sounds like a design problem that should be addressed.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 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