Slide 1 Chapter 7 – Part 1 Data Definition Language & Data Manipulation Language.

Slides:



Advertisements
Similar presentations
Murach’s Java SE 6, C21© 2007, Mike Murach & Associates, Inc.Slide 1.
Advertisements

SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
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.
SQL Keys and Constraints Justin Maksim. Key Declaration Key constraint defined within the CREATE TABLE command Key can be declared using either the PRIMARY.
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-1 David M. Kroenke Database Processing Chapter 7 Structured Query Language.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Spring 2008 Project 1, Lecture 3 Slides adapted from those used by Jeffrey Ullman, via Jennifer.
Slide 1 Chapter 7 – Part 2 Chapter 7 – Part 2 Constraints JOIN statement View.
Transforming Data Models into Database Designs
Using ER/Studio.
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
Database Systems Lecture 5 Natasha Alechina
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
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.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
Relational Database Management Systems. A set of programs to manage one or more databases Provides means for: Accessing the data Inserting, updating and.
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Introduction to SQL.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 UNIT 6: Chapter 7: Introduction to SQL Modern Database Management 9 th Edition Jeffrey A.
SQL Data Definition Language (DDL) Using Microsoft SQL Server 1SDL Data Definition Language (DDL)
FEN  Data Definition: CREATE TABLE, ALTER TABLE  Data Manipulation: INSERT, UPDATE, DELETE  Queries: SELECT SQL: Structured Query Language.
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.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 7 (Part a): Introduction to SQL Modern Database Management 9 th Edition Jeffrey A.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Dec 8, 2003Murali Mani Constraints B term 2004: lecture 15.
Constraints cis 407 Types of Constraints & Naming Key Constraints Unique Constraints Check Constraints Default Constraints Misc Rules and Defaults Triggers.
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.
SQL for Database Construction and Application Processing
CREATE TABLE CREATE TABLE statement is used for creating relations Each column is described with three parts: column name, data type, and optional constraints.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
DBSQL 5-1 Copyright © Genetic Computer School 2009 Chapter 5 Structured Query Language.
SQL introduction 2013.
SQL Structured Query Language. Aims  To introduce the implementation of a Physical design using SQL.  To introduce SQL Data Definition Language (DDL).
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
IS 380 Introduction to SQL This lectures covers material from: database textbook chapter 3 Oracle chapter: 3,14,17.
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.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
There are two types of MySQL instructions (Data Definition Language) DDL: Create database, create table, alter table,,,. (Data Manipulation Language) DML.
Slide 1 Chapter 7 – Part 3 Stored Procedure, Function &Trigger.
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.
Including Constraints. What Are Constraints? Constraints enforce rules at the table level. You can use constraints to do the following: – Enforce rules.
CREATE TABLE ARTIST ( ArtistID int NOT NULL IDENTITY (1,1), Namechar(25) NOT NULL, TEXT ERROR Nationality char (30) NULL, Birthdate numeric (4,0) NULL,
Chapter 3: Relational Databases
SQL constrains and keys. SORTED RESULTS Sort the results by a specified criterion SELECT columns FROM tables WHERE predicates ORDER BY column ASC/DESC;
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
CSC314 DAY 8 Introduction to SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall SQL OVERVIEW  Structured Query Language  The.
Understand Data Definition Language (DDL) Database Administration Fundamentals LESSON 1.4.
IT 5433 LM3 Relational Data Model. Learning Objectives: List the 5 properties of relations List the properties of a candidate key, primary key and foreign.
Oracle sql Online Training By SMART MIND ONLINE TRAINING Website:
Fundamentals of DBMS Notes-1.
SQL: Schema Definition and Constraints Chapter 6 week 6
The Basics of Data Manipulation
Lecture # 13 (After 1st Exam)
Structured Query Language (Data definition Language)
Lecturer: Mukhtar Mohamed Ali “Hakaale”
CS4222 Principles of Database System
Teaching slides Chapter 8.
The Basics of Data Manipulation
CS122 Using Relational Databases and SQL
CS1222 Using Relational Databases and SQL
Data Definition Language
Instructor: Samia arshad
DATABASE Purpose of database
CS122 Using Relational Databases and SQL
SQL (Structured Query Language)
Presentation transcript:

Slide 1 Chapter 7 – Part 1 Data Definition Language & Data Manipulation Language

Slide 2 Contents A.Sport Shop Problem B.Solution

Slide 3 A.Sport Shop Problem PST, a sport shop, has been in success of business lately. Therefore, it makes sense to establish a database to manage their product. To easily managing, they classify their product into difference types which are included type code and type name. In other words, each product type has many products and a product belongs to a product type. The sport product is described by the following properties: product code, product name, quantity, and price.

Slide 4  From the above details, designing a logical diagram with following constraints: The product code and the product type code must be unique. The product quantity must be greater than or equal to 0. The product price must be greater than 0.  The second requirement is generating a physical diagram of the above database.  The last one is creating SQL statement to create all the tables in database.

Slide 5 B.Solution 1.Create Logical Diagram 2.Create Physical Diagram 3.Write SQL Statement to Create Tables 4.Create Constraints 5.Other Requirement

Slide 6 1. Create Logical Diagram  Exercise: Create logical diagram from the requirement.

Slide 7 2. Create Physical Diagram Exercise: Generate physical diagram from the above logical diagram

Slide 8 3. Write SQL Statement to Create Tables 3.1. Database creating 3.2. DDL Code for Product_Types 3.3. DDL Code for Product 3.4. Relationship creating

Slide Database creating  Login SQL server 2005 > Create database named PST company > Create Database PSTCompany; or

Slide DDL Code for Product_Types CREATE TABLE PRODUCT_TYPES ( TYP_ID int not null, TYPCode char(10), TYPName varchar(30), Constraint PK_PRODUCT_TYPES Primary Key (TYP_ID) );

Slide DDL Code for Products CREATE TABLE PRODUCTS ( PRO_ID bigint Primary Key identity, TYP_ID int not null, PROCode char(10), PROName varchar(50), PROQuantity int, PROPrice money );

Slide 12  To create relationship between two tables, using following SQL statement: Alter Table PRODUCTS Add constraint FK1 Foreign Key (TYP_ID) References PRODUCT_TYPES (TYP_ID) on update cascade on delete cascade;  Cascading Updates and Deletes  A cascading update occurs when a change to the parent’s primary key is applied to the child’s foreign key.  A cascading delete occurs when associated child rows are deleted along with the deletion of a parent row Relationship creating

Slide Create Constraints 4.1. Create Unique Constraint 4.2. Create Check Constraint

Slide Create Unique Constraint  To set unique value (Candidate Key) for Pro_Code in Products table, using the following SQL statement: Alter Table PRODUCTS Add Constraint AK_Product Unique (PROCODE);  To set unique value (Candidate Key) for Typ_Code in Product_Types table, using the following SQL statement: Alter Table PRODUCT_TYPES Add Constraint AK_Product_Type Unique (TYPCODE);

Slide Create Check Constraint  To create a constraint to check quantity must be greater than or equal to 0 Alter Table PRODUCTS Add Constraint Chk1 Check (PROQuantity >= 0);  To create a constraint to check product price must be greater than 0 Alter Table PRODUCTS Add Constraint Chk2 Check (PROPrice > 0);

Slide Other Requirements 5.1. Modify Table Problem 5.2. Modify Table Solution

Slide Modify Table Problem  After creating tables, do the following requirements:  Create a product type which includes following information Product type code: Cloth Product type name: Cloth Sport  Create following two products for Cloth product type: First product has PRO1 code, men T-shirt name, 10 quantities and price is 20 $ Second product has PRO2 code, Nike Hat name, 10 quantities and price is 10 $  Then, update quantity of product has PR01 from 10 to 20  Finally, delete the product has PR02 from PRODUCTS table

Slide Modify Table Solution Insert Product Types Insert Products Update Products Delete Products

Slide Insert Product Types  In order to insert a row (record) into Product Types, using following SQL statement: Insert Into PRODUCT_TYPES (Typ_ID, TypCode, TypName) Values (1, ‘Cloth’, ‘Cloth Sport’);

Slide Insert Products  Those products belong to Cloth product type. Therefore, they must prefer to 1 which is Cloth’s ID. Insert Into PRODUCTS (Typ_ID, ProCode, ProName, ProQuantity, ProPrice) Values (1, ‘PRO1’, ‘Men T-shirt’, 10, 20); Insert Into PRODUCTS (Typ_ID, ProCode, ProName, ProQuantity, ProPrice) Values (1, ‘PRO2’, ‘Nike Hat’, 10, 10);

Slide Update Products  In order to update product quantity of ‘PRO1’ to 20, using following SQL statement: Update PRODUCTS Set ProQuantity = 20 Where ProCode = ‘PRO1’;

Slide Delete Products  Using following statement to delete product(s): Delete From PRODUCTS Where ProCode = ‘PRO2’;

Slide 23