How to create a view using procedure in sql?


In this article I have explained about how to create view using Stored Procedure.

You can create view in Stored procedure dynamically. In this example I'm going to create view for sys.tables.


create proc CreateView
as
begin
Declare @SQL varchar(max)
set @SQL ='create view TEST1 as Select * from sys.tables'
exec(@SQL)
end

To run Store Procedure :
  
EXEC CreateView


To Select view Table

select * from TEST1


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: