Câu hỏi phỏng vấn SQL
Câu hỏi

What is a VIEW ?

Câu trả lời

A view in SQL is a virtual table that is created based on the result set of an SQL query. Unlike a table, a view does not store data physically in the database. Instead, it dynamically retrieves data from one or more underlying tables whenever it is queried. Here are some key points about views:

  1. Definition: A view is essentially a saved SQL query that can be treated as a table. It contains rows and columns just like a real table, but the data is derived from the underlying base tables each time the view is accessed[1][2][4].

  2. Creation: Views are created using the CREATE VIEW statement. The syntax typically looks like this:

    sql Copy
    CREATE VIEW view_name AS
    SELECT column1, column2, ...
    FROM table_name
    WHERE condition;

    For example, to create a view that shows all customers from Brazil, you would use:

    sql Copy
    CREATE VIEW Brazil_Customers AS
    SELECT CustomerName, ContactName
    FROM Customers
    WHERE Country = 'Brazil';
    ```[4][11].
  3. Usage: Views can be used to simplify complex queries, provide a layer of security by restricting access to specific data, and present data in a specific format without altering the underlying tables. They can also be used to join data from multiple tables, aggregate data, and hide the complexity of the database schema from the end-users[1][2][5][9].

  4. Advantages:

    • Security: Views can restrict access to specific rows and columns, thus providing a security layer.
    • Simplicity: They simplify complex queries by encapsulating them in a single view.
    • Space Efficiency: Since views do not store data, they save database storage space.
    • Up-to-date Data: Views always show the most current data from the underlying tables[1][2][9].
  5. Limitations:

    • Performance: There can be a slight performance overhead because the view's query is executed every time the view is accessed.
    • Read-Only: Some views are read-...
entry

entry

Gợi ý câu hỏi phỏng vấn

entry

Define a Temp Table

entry

What is PRIMARY KEY ?

middle

What is the difference between WHERE clause and HAVING clause?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào