DATABASE (SQL) DAY 6) VIEW , UNION ,UNION INTERSECT, UNION ALL
* DATABASE VIEW*
* DATABSE VIEW:-VERTUAL TABLE
* DOESN'T PHYSICALLY EXIST IS SQL SERVER.
* THERE ARE FOLLOWING CONCEPT IN A VIEW
1) CREATE VIEW 2)UPDATE VIEW 3)DROP VIEW
:--ALL VIEW IS USE TO TABLE OBJECT
QUERY:-
1)CREATE VIEW QUERY ;-select view command
:- CREATE VIEW viewname AS SELECT stu1.roll,stu1.mobile from stu1;
:- SELECT * FROM viewname;
2)UPDATE VIEW QUERY ; alter view command
:-ALTER VIEW viewname AS SELECT stu1.mobile FROM stu1;
:-SELECT * FROM viewname ;
:-ALTER VIEW viewname AS SELECT stu1.roll FROM stu1;
3)DELETE VIEW QUERY : drop view command
:-DROP VIEW viewname;
:-SELECT * FROM viewname;
*UNION*
* IT USED TO DIFFERENT TABLE
* UNION IS REMOVE DUPLICATE ROW BETWEEN SELECT QUERY.
*QUERY:-
:-CREATE TABLE PRODUCT ( PID INT);
:-CREATE TABLE INVEN (PID INT);
:-INSERT INTO PRODUCT VALUES (101);
:-INSERT INTO PRODUCT VALUES (102);
:-INSERT INTO PRODUCT VALUES (103);
:-INSERT INTO PRODUCT VALUES (104);
:-SELECT * FROM PRODUCT;
:-INSERT INTO INVEN VALUES (101);
:-INSERT INTO INVEN VALUES (102);
:-INSERT INTO INVEN VALUES (105);
:-INSERT INTO INVEN VALUES (106);
:-SELECT * FROM INVEN;
:-SELECT PID FROM PRODUCT UNION SELECT PID FROM INVEN;
*INTERSECT*
*ONLY RECORD IN COMMON BETWEEN TWO TABLE.
* QUERY:-
:-SELECT PID FROM PRODUCT INTERSECT SELECT PID FROM INVEN;
*UNION ALL*
* IT WILL SHOW ALL PRODUCT.
* QUERY:-
:-SELECT PID FROM PRODUCT UNION ALL SELECT PID FROM INVEN;
VIEW , UNION |
Comments
Post a Comment