How to create view in MySQL database

Created at 06-Jan-2024 , By samar

In MySQL, you can use simple CREATE VIEW statement to create a view in database. A view is a saved query that acts like a virtual table. It doesn't store the actual data but provides a way to present the results of a query as if it were a table, making it easier to retrieve specific information without altering the original data.

  • Create view Statement in MySQL

    CREATE VIEW employeeNames as select EmpID, EmpName from employee;
    

    Output

    mysql> CREATE VIEW employeeNames as select EmpID, EmpName from employee;
    Query OK, 0 rows affected (0.02 sec)
    

    You can use above statement to create a view in MySQL table.

  • Employee table structure

    Create table statement to create Employee table.

    You can create the Employee table with columns EmpID, EmpName, Mobile, PresentAddress, Area, City, Country, Qualification and Email.

    CREATE TABLE Employee (
        EmpID INT PRIMARY KEY,
        EmpName VARCHAR(255),
        Mobile VARCHAR(20),
        PresentAddress VARCHAR(255),
        Area VARCHAR(255),
        City VARCHAR(255),
        Country VARCHAR(255),
        Qualification VARCHAR(255),
        Email VARCHAR(255)
    );
    

Back to code snippet queries related sql

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.