Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University

Similar presentations


Presentation on theme: "Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University"— Presentation transcript:

1 Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Ch5 Summary Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University

2 Subquery or Nested query
Subquery or Nested query is one of the most powerful features of SQL Select command This feature enables you to ask complex questions that entail retrieving different types of data or data from different sources A subquery can contain another subquery and so on The DBMS generally evaluates the innermost query first and passes results back to the higher level

3 Subqueries and Sets of Data IN, ALL, ANY, EXISTS
IN Operator Use the IN operator to match values in a list The match is based on equality E.g. WHERE ItemID IN (1,2,30,32,33). This means that the ItemID number must be in this list ANY & ALL Any & All operators combine comparison of numbers with subsets. ANY & ALL work with > or < operators and compare the test value to a list of values Using All operator the test value must be greater than all of the values in the list.

4 Subtraction: NOT IN As the name suggests, this operator is the opposite of IN operator. It gets the rows that are NOT in the defined list

5 Correlated Subqueries
A subquery that refers to data rows in the main query, in which the calculation is recomputed for each entry In other words, the main query and the subquery are both referring to the same table. Therefore for each row in the main query the subquery will re-run

6 Union, Intersect, Except
Union combines data from two tables. All searches and operations performed will treat the two tables as one large table The most important thing to remember when creating a Union, is that data from both tables must match (e.g. EID to EID, Name to Name) The basic version of the command automatically eliminates duplicate rows of data. If you want to keep all rows – even the duplications- use UNION ALL

7 Intersect Operator Except Operator
Returns the rows that appear in both tables Except Operator Returns rows that appear in the first table only. Notice that the result of Except operator depends on which table is listed first

8 Multiple Join Columns The syntax for multiple joins is simple, we expand the on statement by listing both column connections The two sets of columns must be equal at the same time, so they are connected with an AND

9 Reflexive Join or self-join
A Reflexive join means that a table is joined to itself One column in a table is used to match values in a second column in the same table The key to self-joins is to make sure that the columns contain the same type of data, and to create an alias for the second copy of the table

10 Inequality Joins (Theta Join)
Most join statements are simple equality conditions using = sign When comparisons are made with inequality operators (less than, greater than) instead of an equals sign, it is called Inequality or theta join

11 SQL Data Definition Commands
Create Schema A schema is a collection of tables SYNTAX : CREATE SCHEMA AUTHORIZATION DBname Password

12 Create Table This command defines a new table and all of the columns that it will contain Not NULL command is used to identify the key columns for the table DEFAULT assign default values SYNTAX : CREATE TABLE Customer (CustomerID INTEGER NOT NULL, LastName VARCHAR(10), );

13 Constraints Constraints are rules that are enforced by the database system Each constraint is given a name e.g. pkorder You can choose any name, but you should pick one that you will recognize later The primary key constraint list the column or columns that make up the primary key Note that each column in the primary key should also be marked as NOT NULL The foreign key lists the column in the current table that is linked to (reference) a column in the second table

14 Alter Table & Drop Table
These commands enable you to modify the structure of an existing table. Drop command will remove the entire table from the database, including its data and structural definition Alter table is used to ADD or DELETE columns from a table When you drop an entire column, all the data stored in that column will be deleted When you add a new column, it will contain NULL values for any existing rows

15 SQL Data Manipulation Commands
Data manipulation commands are used to change the data within the tables They are used to : Insert data Delete rows Update (change) the values of specific cells Remember that these commands : Operate on sets of data at one time Utilize the power of SELECT and WHERE statements

16 Insert into Insert has 2 versions: Insert into target values …..
This is used to insert one row of data at a time, and is found to be not very useful SELECT ………. FROM……. This is used to select rows and insert them in one time into another table This is very useful in the case of copying data from one table into another based on a certain WHERE condition

17 Delete Delete From table Where Condition
Delete command deletes rows within a table based on WHERE condition, Drop command removes an entire table

18 Update Update command is used to change an entire collection of rows at one time. You use the WHERE clause to specify which set or rows need to be changed SYNTAX: UPDATE TABLE SET COLUMN = NEW COLUMN VALUE WHERE CONDITION


Download ppt "Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University"

Similar presentations


Ads by Google