Solved

MS SQL creatin a view

Posted on 2011-03-08
3
462 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 143

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tempdb log contention 16 49
ms sql + get number in list out of total 7 36
SQL DATEADD 10 70
(sql serv16)ssis 2016 question/check 1 64
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 …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

808 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