My SQL Part3
My SQL Part3
(SELECT column_list (s) FROM ta The subquery (inner query) executes once before the main
query.
ble_name [WHERE]) The result of the subquery is used by the main query (outer
query).
SQL View
VIEWS are virtual tables that do not store any data of
Create View Syntax
their own but display data stored in other tables. In other
CREATE VIEW view_name AS SELECT column1, words, VIEWS are nothing but SQL Queries. A view can
column2...FROM table_name WHERE [condition]; contain all or a few rows from a table. A MySQL view
can show data from one table or many tables.
The parameters are:
CREATE VIEW: The command “CREATE VIEW ‘view
name'” instructs MySQL to create a view object named
‘view name’ in the database.
AS SELECT: The SQL statements to be packed in the
MySQL Views are referred to as “AS SELECT
statements.” A SELECT statement can include data from
one or more tables.
Updating a View
A view can be updated under certain conditions:
The SELECT clause may not contain the keyword DISTINCT.
The SELECT clause may not contain summary functions.
The SELECT clause may not contain set functions.
The SELECT clause may not contain set operators.
The SELECT clause may not contain an ORDER BY clause.
The FROM clause may not contain multiple tables.
The WHERE clause may not contain subqueries.
The query may not contain GROUP BY or HAVING.
Calculated columns may not be updated.
All NOT NULL columns from the base table must be included in the view in order for the INSERT query to function.
Dropping Views
Syntax The SQL DROP View statement is
DROP VIEW view_name; used to delete an existing view,
along with its definition and other
information.
Once the view is dropped, all the
permissions for it will also be
removed. We can also use this
statement to drop indexed views.
Index
Create Index Syntax A database index is a data structure
CREATE UNIQUE INDEX that improves the speed of
index_name ON table_name operations in a table.
( column1, column2,...); Indexes can be created using one or
Displaying INDEX Information more columns.