Bird
0
0

Given tables Employees(EmployeeID, Name, Salary, DeptID) and Departments(DeptID, DeptName), which SQL creates this view correctly?

hard📝 Application Q8 of 15
SQL - Views
You want to create a view that shows only employees' names and their department names, hiding salaries for security. Given tables Employees(EmployeeID, Name, Salary, DeptID) and Departments(DeptID, DeptName), which SQL creates this view correctly?
ACREATE VIEW EmpDeptView AS SELECT E.Name, D.DeptName FROM Employees E JOIN Departments D ON E.DeptID = D.DeptID;
BCREATE VIEW EmpDeptView AS SELECT Name, Salary, DeptName FROM Employees JOIN Departments ON Employees.DeptID = Departments.DeptID;
CCREATE VIEW EmpDeptView AS SELECT EmployeeID, Salary FROM Employees;
DCREATE VIEW EmpDeptView AS SELECT * FROM Employees;
Step-by-Step Solution
Solution:
  1. Step 1: Identify required columns and join

    We need employee names and department names, joining on DeptID.
  2. Step 2: Check each option for correct columns and join

    CREATE VIEW EmpDeptView AS SELECT E.Name, D.DeptName FROM Employees E JOIN Departments D ON E.DeptID = D.DeptID; selects Name and DeptName with proper join; others include Salary or wrong columns.
  3. Final Answer:

    CREATE VIEW EmpDeptView AS SELECT E.Name, D.DeptName FROM Employees E JOIN Departments D ON E.DeptID = D.DeptID; -> Option A
  4. Quick Check:

    View hides salary, shows name and department [OK]
Quick Trick: Join tables in view to combine related info securely [OK]
Common Mistakes:
MISTAKES
  • Including salary when it should be hidden
  • Selecting all columns with *
  • Missing join condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes