How to create view in MySQL database
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) );
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
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.
Random Code Snippet Queries: Sql
- How to retrieve data from two tables with one SQL statement
- Cannot drop index 'fk_role_id': needed in a foreign key constraint
- Drop foreign id column (user_id) in MySQL
- SQLSTATE[01000]: Warning: 1265 Data truncated for column 'visibility' at row 1
- SQL query to delete all rows older than 30 days
- How to get yesterday's date in MySQL ?
- Change existing MySQL table column id to autoincrement
- How to check column exists or not in table using MySQL
- How to create a new table from existing table in SQL
- 1553 Cannot drop index 'posts_user_id_foreign': needed in a foreign key constraint
- Get full name of a person in SQL using function
- How to get a list of MySQL views?
- How to show database tables in mysql using command line
- SQL query to delete records older than 6 months
- How to create function in MySQL ?
- How to drop function in MySQL ?
- Insert multiple rows in a single MySQL query
- Get comma separated ids from table using MySQL
- Get data in random order with limit from table using mysql
- Get number of connections being used by a specific user in MySQL
- Clear the terminal screen in MySQL within the Windows powershell
- Get create table Query from existing table in phpMyAdmin
- Database connection using mySQLi with object-oriented
- Create Employee table in MySQL
- Difference between SQL and NoSQL databases