1 SQL Tarek El-Shishtawy Professor Ass. Of Computer Engineering.

Slides:



Advertisements
Similar presentations
SQL Rohit Khokher.
Advertisements

Chapter 4 5 6_ SQL SQL Is: Structured Query Language
SQL’s Data Definition Language (DDL) n DDL statements define, modify and remove objects from data dictionary tables maintained by the DBMS n Whenever you.
Database Basics I101 Summer 2006 Copyright 2004, Matt Hottell.
Structured Query Language - SQL Carol Wolf Computer Science.
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 9: Data Definition Language.
1 © Prentice Hall, 2002 Chapter 7: SQL Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden.
1 IS 4420 Database Fundamentals Chapter 7: Introduction to SQL Leon Chen.
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
30-Jun-15 SQL A Brief Introduction. SQL SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell”
Attribute databases. GIS Definition Diagram Output Query Results.
Database Management System LICT 3011 Eyad H. Elshami.
Database Systems Lecture 5 Natasha Alechina
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
Introduction to SQL  SQL or sequel  It is a standardised language with thousands of pages in the standard  It can be in database system through GUI,
Oracle Data Definition Language (DDL)
Copyright © Curt Hill SQL The Data Definition Language.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
Database Design lecture 3_1 1 Database Design Lecture 3_1 Data definition in SQL.
ZEIT2301 Design of Information Systems SQL: Creating a Database School of Engineering and Information Technology Dr Kathryn Merrick.
Chapter Six Professor Adams’ Slides. Note that entities are shadowed, tables are not. Note that entities have no physical existence (blueprint) Note.
Database System SQL November 1st, 2009 Software Park, Bangkok Thailand Pree Thiengburanathum College of Arts and Media Chiang Mai University.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
Guofeng Cao CyberInfrastructure and Geospatial Information Laboratory Department of Geography National Center for Supercomputing Applications (NCSA) University.
Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”
CSC 2720 Building Web Applications Database and SQL.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
SQL Data Definition Language (DDL) Using Microsoft SQL Server 1SDL Data Definition Language (DDL)
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
SQL FUNDAMENTALS SQL ( Structured Query Language )
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
1 Creating and Modifying Database Objects. 2 An Oracle database consists of multiple user accounts Each user account owns database objects Tables Views.
SQL: DDL John Ortiz Cs.utsa.edu.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
Lec 3- B Database Integrity 1. Overview Define a database using SQL data definition language Work with Views Write single table queries Establish referential.
© 2005 by Prentice Hall 1 Chapter 7: Introduction to SQL Modern Database Management 7 th Edition Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Advanced Database CS-426 Week 1 - Introduction. Database Management System DBMS contains information about a particular enterprise Collection of interrelated.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
SQL: Part 1 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram. Not for commercial.
DBSQL 5-1 Copyright © Genetic Computer School 2009 Chapter 5 Structured Query Language.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
1 SQL-2 Tarek El-Shishtawy Professor Ass. Of Computer Engineering.
1 Chapter 2: Creating and Modifying Database Objects.
Sql DDL queries CS 260 Database Systems.
Week 8-9 SQL-1. SQL Components: DDL, DCL, & DML SQL is a very large and powerful language, but every type of SQL statement falls within one of three main.
SQL Overview Structured Query Language
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
1 © Prentice Hall, 2002 Chapter 7: SQL Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden.
* Database is a group of related objects * Objects can be Tables, Forms, Queries or Reports * All data reside in Tables * A Row in a Table is a record.
CS263 Information Modeling Course tutor: Tony Browne Some diagrams in these notes are small when printed 6.
Lecture # 24 Introduction to SQL Muhammad Emran Database Systems.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
Aga Private computer Institute Prepared by: Srwa Mohammad
Creating Database Objects
ORACLE SQL Developer & SQLPLUS Statements
SQL 101.
CS4222 Principles of Database System
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
ICT Database Lesson 2 Designing a Database.
Creating Database Objects
SQL (Structured Query Language)
Presentation transcript:

1 SQL Tarek El-Shishtawy Professor Ass. Of Computer Engineering

2 SQL - Advantages Stands for Structured Query Language Stands for Structured Query Language Low training cost – simple language Low training cost – simple language Fixed rigid simple syntax Fixed rigid simple syntax Independent of Operating system Independent of Operating system Independent of Data Base Independent of Data Base Provides interconnection between forms, reprts and all applications with the DB Provides interconnection between forms, reprts and all applications with the DB

3 SQL Categories DDL DDL Data Definition Language Data Definition Language Used to create data base elements such as tables, views Used to create data base elements such as tables, views DML DML Data Manipulation Language Data Manipulation Language Used to process data such as selecting, Inserting, deleting data Used to process data such as selecting, Inserting, deleting data DCL DCL Data Control Language Data Control Language Used by database administrator to give previelages to users, back up, tuning performance, Used by database administrator to give previelages to users, back up, tuning performance,

4 DDL, DML, DCL, and the database development process

5 Relational Tables Table Name Table Name COURSE COURSE Field Names Field Names CRS : Code for the course CRS : Code for the course CTITLE Course Title CTITLE Course Title CHRSCourse Hours CHRSCourse Hours CHRSWCourse Hours per week CHRSWCourse Hours per week

6 Relational Model

7 Note the following Note the following The intersection between each column and row has only one value The intersection between each column and row has only one value No two rows has identical values No two rows has identical values No order is assumed. No order is assumed. When inserting new row, its location is not known When inserting new row, its location is not known The table can be represented as The table can be represented as COURSE (CRS, CTITLE, CHRS, CHRSW) COURSE (CRS, CTITLE, CHRS, CHRSW)

8 ORACLE Basic data types String types String types CHAR(n) CHAR(n) fixed-length character data fixed-length character data n characters long n characters long VARCHAR2(n) VARCHAR2(n) variable length character data variable length character data maximum 4000 bytes in oracle 9 I maximum 4000 bytes in oracle 9 I LONG LONG variable-length character data variable-length character data up to 4GB up to 4GB Maximum 1 per table Maximum 1 per table

9 ORACLE Basic data types Numeric types Numeric types NUMBER(p,q) NUMBER(p,q) general purpose numeric data type general purpose numeric data type Total width = p, out of which q decimal numbers Total width = p, out of which q decimal numbers INTEGER(p) INTEGER(p) signed integer, p digits wide signed integer, p digits wide FLOAT(p) FLOAT(p) floating point in scientific notation with p binary digits precision floating point in scientific notation with p binary digits precision Date/time type Date/time type DATE DATE length date/time in dd-mm-yyyy/hh:mm:ss form length date/time in dd-mm-yyyy/hh:mm:ss form

10 Table Keys Primary Keys Primary Keys Uniqueness Uniqueness NOT NULL NOT NULL Minimum Number of columns Minimum Number of columns Foreign Keys Foreign Keys Used to relate rows of two or more tables Used to relate rows of two or more tables Foreign key at the child table should be of the same type (and values) of the primary key at the parent table Foreign key at the child table should be of the same type (and values) of the primary key at the parent table

11 Example of relationships OFFLOC 01RIYAD 02JEDDAH Table LOCATION Parent CRSOFFODATE SEP NOV NOV FEB-92 Table Offer Child Primary Key Foreign Key Comes from LOCATION.OFF

12 Example of Database Tables COURSE (CRS, CTITLE, CHRS, CHRSW) COURSE (CRS, CTITLE, CHRS, CHRSW) OFFER (CRS, OFF, ODATE) OFFER (CRS, OFF, ODATE) LOCATION (OFF, LOC) LOCATION (OFF, LOC)

13 Questions Determine suitable data types and lengths for fields in previous tables Determine suitable data types and lengths for fields in previous tables If we want to add data for PERSONS who ATTEND offer of courses. How many tables should be added? What relations are required? If we want to add data for PERSONS who ATTEND offer of courses. How many tables should be added? What relations are required? Note data of persons are ID, Name, and address. Note data of persons are ID, Name, and address. Determine also primary and foreign key for new tables and suitable field types and widths. Determine also primary and foreign key for new tables and suitable field types and widths.

14 Selecting data from the table General Form General Form Select Column Names From Table Name [ Where Conditions] /* Optional where */ Examples for Examples for COURSE (CRS, CTITLE, CHRS, CHRSW) COURSE (CRS, CTITLE, CHRS, CHRSW) SELECT CRS, CTITLE FROM COURSE;

15 Example Continued SELECT CTITLE, CHRSW FROM COURSE; SELECT * FROM COURSE; SELECT CTITLE, CHRSW FROMCOURSE WHERECRS = 706;

16 Example Continued SELECT * FROMCOURSE WHERECHRS >= 60 AND CHRSW = 15; SELECT CTITLE, CHRSW FROMCOURSE WHERE CHRS >= 60 and CHRS = 60 and CHRS < =100;

17 Continued SELECT CTITLE, CHRSW FROMCOURSE WHERE CHRS BETWEEN 60 and 100; SELECT CTITLE, CHRSW FROMCOURSE WHERE CHRS >= 60 OR CRS = 706;

18