[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

MS SQL creatin a view

Posted on 2011-03-08
3
Medium Priority
?
495 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 120 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 260 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 120 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

873 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