If you use the SHOW TABLE command to view all tables in the classicmodels database, you will see the view salesPerOrder is showing up in the list. ORDER BY total DESC Code language: SQL (Structured Query Language) ( sql ) This statement uses the CREATE VIEW statement to create a view that represents total sales per order. Let’s take a look at the orderDetails table from the sample database: Let’s take some example of using the CREATE VIEW statement to create new views. If you want to explicitly create a view in a given database, you can qualify the view name with the database name. MySQL allows you to use the ORDER BY clause in the SELECT statement but ignores it if you select from the view with a query that has its own ORDER BY clause.īy default, the CREATE VIEW statement creates a view in the current database. The SELECT statement can query data from tables or views. However, you can explicitly specify the column list for the view by listing them in parentheses following the view name.įinally, specify a SELECT statement that defines the view. By default, the columns of the view are derived from the select list of the SELECT statement. Third, specify a list of columns for the view. If the view does not exist, the OR REPLACE has no effect. Second, use the OR REPLACE option if you want to replace an existing view if the view already exists. Because views and tables in the same database share the same namespace, the name a view cannot the same as the name of an existing table. The name of the view is unique in a database. Here is the basic syntax of the CREATE VIEW statement: CREATE VIEW view_name ĪS select- statement Code language: SQL (Structured Query Language) ( sql )įirst, specify the name of the view that you want to create after the CREATE VIEW keywords. The CREATE VIEW statement creates a new view in the database. Introduction to MySQL CREATE VIEW statement Summary: in this tutorial, you will learn how to use the MySQL CREATE VIEW statement to create a new view in the database.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |