In addition, MySQL even allows you to create a view that does not refer to any table. This picture illustrates a view based on columns of multiple tables: MySQL allows you to create a view based on a SELECT statement that retrieves data from one or more tables. For this reason, sometimes, a view is referred to as a virtual table. When you issue the SELECT statement against the view, MySQL executes the underlying query specified in the view’s definition and returns the result set. Note that a view does not physically store the data. For example, you can query data from the customerPayments view using the SELECT statement: SELECT * FROM customerPayments Īs you can see, the syntax is much simpler. Now, you can reference the view as a table in SQL statements. Once you execute the CREATE VIEW statement, MySQL creates the view and stores it in the database. This statement creates a view customerPayments based on the above query above: CREATE VIEW customerPayments To create a new view you use the CREATE VIEW statement. This named query is called a database view, or simply, view.īy definition, a view is a named query stored in the database catalog. sql file so that later you can open and execute it from MySQL Workbench or any other MySQL client tools.Ī better way to do this is to save the query in the database server and assign a name to it. ![]() ![]() One way to do this is to save the query in a file, either. Next time, if you want to get the same information including customer name, check number, payment date, and amount, you need to issue the same query again. This query returns data from both tables customers and payments using the inner join: SELECTĬode language: SQL (Structured Query Language) ( sql ) ![]() Let’s see the following tables customers and payments from the sample database. Summary: in this tutorial, you will learn about MySQL views and how to manipulate views effectively.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |