Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Combining two views in SQL Server
WhatsApp
Venkatesan Jayakantham
13y
4.6
k
0
0
25
Blog
Let's talk about views in SQL Server. Views are nothing but virtual tables which covers the table in SQL Server.
Am creating two tables,
DROP TABLE VENKAT_TABLE
GO
CREATE TABLE VENKAT_TABLE(ID INT, NAME VARCHAR(100))
GO
INSERT INTO VENKAT_TABLE VALUES(1,'SUBA')
GO
INSERT INTO VENKAT_TABLE VALUES(1,'ARUN')
GO
DROP TABLE VENKAT_SECOND_TABLE
GO
CREATE TABLE VENKAT_SECOND_TABLE(ID INT, AGE INT)
GO
INSERT INTO VENKAT_SECOND_TABLE VALUES(1,20)
GO
INSERT INTO VENKAT_SECOND_TABLE VALUES(1,30)
GO
-- Now am creating the views for the tables.
-- Views are nothing but virtual table which is like a mask on the table. For security reasons, instead of allowing the user to access the tables directly we will use views.
CREATE VIEW VENKAT_VIEW
AS
SELECT * FROM VENKAT_TABLE
GO
CREATE VIEW VENKAT1_VIEW
AS
SELECT * FROM VENKAT_TABLE
GO
CREATE VIEW VENKAT_SECOND_VIEW
AS
SELECT * FROM VENKAT_SECOND_TABLE
GO
Joining two views
------------------------------------------------------------------------------------
SELECT V1. * FROM VENKAT_VIEW V1 INNER JOIN VENKAT_SECOND_VIEW V2
ON V1.ID=V2.ID
Merging the results sets of the view.
(For merging the result set, we can use union all or union operator)
------------------------------------------------------------------------------------
SELECT * FROM VENKAT1_VIEW UNION ALL
SELECT * FROM VENKAT_VIEW
Cheers,
Venkatesan Prabu .J
Head -
http://www.kaashivinfotech.com/
http://venkattechnicalblog.blogspot.com/
Combining two views in SQL Server
Up Next
Advantages and Disadvantages of views in Sql Server
Ebook Download
View all
SQL Queries For Beginners
Read by 18.3k people
Download Now!
Learn
View all
Membership not found