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

Slides:



Advertisements
Similar presentations
Manipulating Data Schedule: Timing Topic 60 minutes Lecture
Advertisements

Virtual training week 4 structured query language (SQL)
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
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.
Introduction to Structured Query Language (SQL)
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
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 9: Data Definition Language.
Using SQL to create tables Ways of using Databases.
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.
Database Management System LICT 3011 Eyad H. Elshami.
Chapter 5 Data Manipulation and Transaction Control Oracle 10g: SQL
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 10: Data Definition Language.
Oracle Data Definition Language (DDL)
Structured Query Language S Q L. What is SQL It is a database programming language developed by IBM in the early 1970’s. It is used for managing and retrieving.
1 IT420: Database Management and Organization SQL: Structured Query Language 25 January 2006 Adina Crăiniceanu
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Database Design lecture 3_1 1 Database Design Lecture 3_1 Data definition in SQL.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
Chapter Four Objectives Introduction to SQL Types of SQL statements Concepts of DDL & DML Creating Tables Restrictions on Tables Data Definition Language(DDL)
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
1 SQL Tarek El-Shishtawy Professor Ass. Of Computer Engineering.
ACTION QUERIES (SQL COMMANDS ) STRUCTURED QUERY LANGUAGE.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
Nitin Singh/AAO RTI ALLAHABAD 1 SQL Nitin Singh/AAO RTI ALLAHABAD 2 OBJECTIVES §What is SQL? §Types of SQL commands and their function §Query §Index.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Intro to SQL| MIS 2502  Spacing not relevant › BUT… no spaces in an attribute name or table name  Oracle commands keywords, table names, and attribute.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
Session 2: SQL (A): Parts 1 and 2 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
Chapter 9 Constraints. Chapter Objectives  Explain the purpose of constraints in a table  Distinguish among PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK,
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Copyright  Oracle Corporation, All rights reserved. Introduction.
CREATE TABLE CREATE TABLE statement is used for creating relations Each column is described with three parts: column name, data type, and optional constraints.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
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.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
IS 380 Introduction to SQL This lectures covers material from: database textbook chapter 3 Oracle chapter: 3,14,17.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
Populating and Querying tables Insert, Update, Delete and View (DML)
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
UNIVERSITAS BINA DARMA 2013 DATA DEFINITION LANGUAGE (DDL)
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
SQL Statements SELECT INSERTUPDATEDELETECREATEALTERDROPRENAMETRUNCATECOMMITROLLBACKSAVEPOINTGRANTREVOKE Data Retrieval Language (DRL) Data Retrieval Language.
Fundamentals of DBMS Notes-1.
Insert, Update and the rest…
Introduction to Structured Query Language(SQL)
Introduction to Oracle9i: SQL
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
The Basics of Data Manipulation
Database Management System
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Data Definition Language
កម្មវិធីបង្រៀន SQL Programming ជាភាសាខ្មែរ Online SQL Training Course
កម្មវិធីបង្រៀន SQL Programming ជាភាសាខ្មែរ Online SQL Training Course
Trainer: Bach Ngoc Toan– TEDU Website:
Presentation transcript:

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

2 DDL examples Creating tables CREATE TABLETableName (Column-definition [,Column-definition] ) ; Column-definition is ColumnNamedata-type[Constraint]

3 Naming tables Start with Alphabitical Start with Alphabitical Special characters as ( _, #, ) and numbers are allowed Special characters as ( _, #, ) and numbers are allowed Not case sensitive (emp, Emp, EMP) Not case sensitive (emp, Emp, EMP) Unique name within account Unique name within account Not an sql reserved word as Select, Update, …. Not an sql reserved word as Select, Update, …. Not more that 30 characters Not more that 30 characters

4 Example ًُExample for creating table PERSONS ًُExample for creating table PERSONS CREATE TABLE PERSONS ( CODENUMBER(3,0)NOT NULL, NAMEVARCHAR2(50)NOT NULL, NAMEVARCHAR2(50)NOT NULL, ADDRESSVARCHAR2(50) ADDRESSVARCHAR2(50)); Constraints Example NOT NULL NOT NULL PRIMAEY KEY PRIMAEY KEY

5 Default values CREATE TABLE INVOICE ( INV_NUMNUMBER(4,0)NOT NULL, INV_TOTALNUMBER(10,3)DEFAULT 0, INV_TOTALNUMBER(10,3)DEFAULT 0, INV_DATEDATEDEFAULT SYSDATE INV_DATEDATEDEFAULT SYSDATE ); );

6 Removing table Syntax DROP TABLE TableName ; Example DROP TABLE PERSONS; Note: Note: The difference between Drop and DELETE keywords The difference between Drop and DELETE keywords

7 Changing table design ALTER TABLE Adding new fields Adding new fields ALTER TABLE PERSONS ADD (IDNUMBERVARCHAR2(10) ); Modifying Field definition Modifying Field definition ALTER TABLE PERSONS MODIFY (IDNUMBER VARCHAR2(20));

8 Checking All tables in the current account All tables in the current account Select * from tab; Table design Table design Desc table_name;

9 Examples of DML

10 Inserting data Syntax Syntax INSERT INTO TableName [(ColumnName [,ColumnName]...)] VALUES(Value [,Value ]... ) ; Or Or INSERT INTO tablename (first_column,...last_column) (first_column,...last_column) values (first_value,...last_value); values (first_value,...last_value);

11 Inserting INSERT INTO PERSONS (CODE, NAME, ADDRESS, PERSONID, BIRTHDATE) VALUES (1,’Ahmed’, ‘Cairo’, ‘101-99’, ’12-SEP-1982’); Note: Default date is in format DD-MON-YYYY JAN, FEB, MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC To confirm write COMMIT; To confirm write COMMIT; To undo write ROLLBACK; To undo write ROLLBACK;

12 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;

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

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

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

16