Junior — Middle
Can you explain what is meant by view in the context of a database?
sobes.tech AI
Answer from AI
In the context of databases, a view is a virtual table that is generated based on the result of a query on one or more tables. It does not store data physically but displays data dynamically when accessed.
For example, if there are Employees and Departments tables, you can create a view that shows employees along with their department names:
CREATE VIEW EmployeeDepartment AS
SELECT e.Name, d.DepartmentName
FROM Employees e
JOIN Departments d ON e.DepartmentId = d.Id;
Views simplify complex queries, provide data security (by showing only necessary columns), and improve code readability.