Presentation is loading. Please wait.

Presentation is loading. Please wait.

DBSQL 5-1 Copyright © Genetic Computer School 2009 Chapter 5 Structured Query Language.

Similar presentations


Presentation on theme: "DBSQL 5-1 Copyright © Genetic Computer School 2009 Chapter 5 Structured Query Language."— Presentation transcript:

1 DBSQL 5-1 Copyright © Genetic Computer School 2009 Chapter 5 Structured Query Language

2 DBSQL 5-2 Copyright © Genetic Computer School, Singapore 2009 Chapter 5 Overview History of SQL Standardized Relational Language Types of SQL Commands Domain Types in SQL Data Definition Language Basic Query and Nested-Query Operations Data Manipulation Language Table Constraints

3 DBSQL 5-3 Copyright © Genetic Computer School, Singapore 2009 History of SQL SQL was developed under the name SEQUEL It was a DML based project to support relational DBMS SEQUEL was chosen as the language for System R

4 DBSQL 5-4 Copyright © Genetic Computer School, Singapore 2009 Standardized Relational Language Reduced training cost Enhanced productivity Application portability Application longevity Reduced dependence on a single vendor

5 DBSQL 5-5 Copyright © Genetic Computer School, Singapore 2009 Types of SQL Commands Data Definition Language (DDL) Data Manipulation Language (DML) Data Control Language Commands (DCL)

6 DBSQL 5-6 Copyright © Genetic Computer School, Singapore 2009 Structure of SQL Commands SQL DDL DMLL DCL CREATE ALTER DROP SELECT DELETE INSERT UPDATE GRAND REVOKE

7 DBSQL 5-7 Copyright © Genetic Computer School, Singapore 2009 Data Types in SQL

8 DBSQL 5-8 Copyright © Genetic Computer School, Singapore 2009 Cont’

9 DBSQL 5-9 Copyright © Genetic Computer School, Singapore 2009 Cont’

10 DBSQL 5-10 Copyright © Genetic Computer School, Singapore 2009 Examples

11 DBSQL 5-11 Copyright © Genetic Computer School, Singapore 2009 Data Definition Language Commands  Define structure and relations of a specific data and table.  Edit or modify the structure of the database created to enhance performance and reliability. Create a Database Using the database Create a table Using the Description Inserting values into a table

12 DBSQL 5-12 Copyright © Genetic Computer School, Singapore 2009 SQL DDL commands Creating a Database Syntax: Create database ; Using the database Syntax: Use ;

13 DBSQL 5-13 Copyright © Genetic Computer School, Singapore 2009 Cont’ Creating a Table Syntax: Create table ; Using the description Syntax: Desc ;

14 DBSQL 5-14 Copyright © Genetic Computer School, Singapore 2009 Cont’ Inserting values into a table Syntax: INSERT INTO (column_name1, column_name2….column_nameN) VALUES (‘value1’, ‘value2’,...’valueN’); Viewing values in a table Syntax: SELECT * from ;

15 DBSQL 5-15 Copyright © Genetic Computer School, Singapore 2009 Basic Query Operations Selection Operation SQL SELECT SQL DISTINCT SQL WHERE SQL AND|OR SQL IN SQL BETWEEN SQL WILDCARDS SQL LIKE SQL ORDER BY SQL GROUP BY SQL AGGREGATE FUNTIONS (MIN, MAX… ) SQL HAVING SQL ALIAS| AS

16 DBSQL 5-16 Copyright © Genetic Computer School, Singapore 2009 Nested Sub-queries Syntax: Select | ( ) From Where IN (Select … From Where );

17 DBSQL 5-17 Copyright © Genetic Computer School, Singapore 2009 Cont’ Other operators: NOT EXIST ANY ALL IN

18 DBSQL 5-18 Copyright © Genetic Computer School, Singapore 2009 SQL DML Commands Adding a row into a table Updating a table data Deleting data in a relation Table modification commands Adding a column into a table Modifying a column Changing a column Dropping a column

19 DBSQL 5-19 Copyright © Genetic Computer School, Singapore 2009 Cont’ Adding a row into a table Syntax: INSERT INTO (, … ) VALUES (‘value1’, ‘value2’… ‘valueN’); Updating a table data Syntax: UPDATE SET = ‘new value’ Where ;

20 DBSQL 5-20 Copyright © Genetic Computer School, Singapore 2009 Cont’ Deleting data in a relation Syntax: DELETE FROM Where ;

21 DBSQL 5-21 Copyright © Genetic Computer School, Singapore 2009 Table Data Modification Adding a column into a table Syntax: ALTER table ADD ; Modifying a column Syntax: ALTER table MODIFY ;

22 DBSQL 5-22 Copyright © Genetic Computer School, Singapore 2009 Cont’ Changing a column name Syntax: ALTER table CHANGE ; Dropping a column Syntax: ALTER table DROP column ;

23 DBSQL 5-23 Copyright © Genetic Computer School, Singapore 2009 Table Constraints Constraints are the characteristics set to a given attribute or column. Remember that when a table is created in various SQL applications, a data type should be assigned as well as other pre-defined properties.

24 DBSQL 5-24 Copyright © Genetic Computer School, Singapore 2009 Cont’ NOT NULL UNIQUE FOREIGN KEY PRIMARY KEY CHECK ON DELETE CASCADE ON DELETE SET NULL

25 DBSQL 5-25 Copyright © Genetic Computer School, Singapore 2009 End


Download ppt "DBSQL 5-1 Copyright © Genetic Computer School 2009 Chapter 5 Structured Query Language."

Similar presentations


Ads by Google