SQL Class 4 PPT
SQL Class 4 PPT
WINDOW FUNCTIONS
VIEWS
STORED PROCEDURES
INDEXES
VIEWS IN SQL
• A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database.
• You can add SQL statements and functions to a view and present the data as if the data were coming from one single table.
• A stored procedure is a prepared SQL code that you can save, so the code can be reused over and over again.
• So if you have an SQL query that you write over and over again, save it as a stored procedure, and then just call it to execute it.
• You can also pass parameters to a stored procedure, so that the stored procedure can act based on the parameter value(s) that is
passed.
INDEXES IN SQL
• Indexes are references to data which are used by queries to find data from tables quickly.
• It cannot be viewed by the users and just used to speed up the database access.
• Without index, the query engine checks every row in the table from beginning till the end- TABLE SCAN
1. Single-Column
Index:
-- Create a single-column index on customer_id
CREATE INDEX idx_customer_id ON customer_orders(customer_id);
2. Composite Index:
3. Unique Index: