Solved

Dynamic View T-SQL

Posted on 2013-05-22
5
369 Views
Last Modified: 2013-05-24
I came across info on Dynamic Views in T-SQL.  I am unclear on what they are (it is a view with dynamic code ?) and when they can be used.   Thanks for any feedback.
0
Comment
Question by:fjkaykr11
  • 2
  • 2
5 Comments
 
LVL 57

Assisted Solution

by:Raja Jegan R
Raja Jegan R earned 334 total points
ID: 39189839
No, its not dynamic views but it is Dynamic Management Views and more details from MSDN below:
http://msdn.microsoft.com/en-us/library/ms188754%28v=sql.110%29.aspx
0
 
LVL 16

Assisted Solution

by:Surendra Nath
Surendra Nath earned 166 total points
ID: 39189862
As said by rrjegan17, there are no dynamic views in SQL Server....

As far as I know a View definition dont accept dynamic code....

But at the time of creation of a view you can create it dynamically, probably you are looking one of such thing and saying that as a dynamic view.

For example:

declare @tableName varchar(50)
set @tableName = 'abcd'
declare @sql varchar(2000)
set @sql = 'create view viw_'+@tableName + ' as Select * from ' + @TableName
exec(@sql)

Open in new window


the above code will create a view dynamically for you, depending on the variables...
0
 
LVL 3

Author Comment

by:fjkaykr11
ID: 39193103
thanks for the replies. In this MSDN link they refer to Dynamic Views (do they really mean Dynamic View Management) ?
http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/558edef0-9618-438e-b670-f421c0ecac92/
0
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 334 total points
ID: 39193366
No, its Dynamic SQL and not Dynamic Views..
Either you can create a view or do any operation with Dynamic SQL as mentioned by Neo_jarvis also above..
For a good start on Dynamic SQL you can use the below link:
http://www.benkotips.com/pages/DynamicSQL.aspx

But be a bit careful while using Dynamic SQL since the code is not parsed until it is executed, and it can potentially introduce security vulnerabilities that you do not want.
0
 
LVL 3

Author Closing Comment

by:fjkaykr11
ID: 39195135
Thanks for clarifying this. I appreciate the feedback.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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