How to create a user view using a table in a database management system?

How to create a user view using a table in a database management system?

How can we write it in SQL code?

I tried to do this ... CREATE VIEW VIEW3 AS SELECT MGRSSN, FNAME, LNAME, BDATE, SALARY FROM DEPARTMENT, EMPLOYEE WHERE DEPARTMENT.MGRSSN = EMPLOYEE.SSN;

+4
source share
1 answer

Not knowing the exact structure of the table, I cannot help you complete the query 100%, but this should help you in the right direction and solve your problem:

CREATE VIEW Syntax:

CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition

You are doing the wrong JOIN:

CREATE VIEW VIEW3 AS SELECT MGRSSN, FNAME, LNAME, BDATE, 
SALARY FROM DEPARTMENT, EMPLOYEE WHERE DEPARTMENT.MGRSSN = EMPLOYEE.SSN;

It should look like:

CREATE VIEW VIEW3
AS SELECT MGRSSN, FNAME, LNAME, BDATE, SALARY  
FROM DEPARTMENT a, EMPLOYEE b
WHERE a.MGRSSN = b.SSN

You just need to request it:

SELECT * FROM [VIEW3]

For further reading, I suggest you look in the SQL documentation for CREATE VIEW statements and learn how to work with a virtual table.

0

Source: https://habr.com/ru/post/1536879/


All Articles