?
Solved

MS SQL creatin a view

Posted on 2011-03-08
3
Medium Priority
?
485 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

765 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