©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.

Slides:



Advertisements
Similar presentations
Fall 2005 ICS184/EECS116 – Notes 08 1 ICS 184/EECS116: Introduction to Data Management Lecture Note 8 SQL: Structured Query Language -- DDL.
Advertisements

Database Design -- Basic SQL
Chapter 4: Immediate SQL Complex Queries Complex Queries Views Views Modification of the Database Modification of the Database Joined Relations Joined.
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.
SQL Sangeeta Devadiga CS157A, Fall Outline Background Data Definition Basic Structure Set Operation.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 SQL: Data Definition, Constraints, and Basic Queries and Updates.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Modification of the Database – Deletion Delete all account records at the Perryridge branch.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
1 CMSC424, Spring 2005 CMSC424: Database Design Lecture 7.
The Relational Model Lecture 3 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) From ER to Relational.
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 System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
MySQL Tutorial Introduction to Database. Learning Objectives  Read and write Data Definition grammar of SQL  Read and write data modification statements.
CIS552SQL1 Data Definition Language Insertions Basic Query Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations.
Chapter 6: Integrity Objective Key Constraints (Chapter 2) Cardinality Constraints (Chapter 2) Domain Constraints Referential Integrity Assertions Triggers.
Chapter 3: SQL Data Definition Language Data Definition Language Basic Structure of SQL Basic Structure of SQL Set Operations Set Operations Aggregate.
Copyright © Curt Hill SQL The Data Definition Language.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
Chapter 6: Integrity and Security Thomas Nikl 19 October, 2004 CS157B.
Chapter 4 Intermediate SQL: Integrity Constraints.
©Silberschatz, Korth and Sudarshan6.1Database System Concepts Chapter 6: Integrity and Security Domain Constraints Referential Integrity Assertions Triggers.
Chapter 4: Advanced SQL. 4.2Unite International CollegeDatabase Management Systems Chapter 4: Advanced SQL SQL Data Types and Schemas Integrity Constraints.
3.1 Chapter 3: SQL. 3.2 Chapter 3: SQL Basic Query Structure Set Operations Aggregate Functions Null Values Nested Subqueries Complex Queries Views Modification.
Holliday - COEN 1781 Introduction to SQL. Holliday - COEN 1782 DB Tables and SQL The data is stored in the database in relations or tables Data types.
CSE314 Database Systems Lecture 4 Basic SQL Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
3.1 Chapter 3: SQL Schema used in examples p (omit 3.8.2, , 3.11)
-- Introduction to database principles Maoying Wu March 25, 2013 Chapter 4: Advanced SQL (1)
1 The Relational Model Instructor: Mohamed Eltabakh
Chapter 8 Part 1 SQL-99 Schema Definition, Constraints, Queries, and Views.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Modification of the Database – Deletion Delete all tuples from the loan relation. delete.
CSC 2720 Building Web Applications Database and SQL.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
CSc-340 3b1 Intermediate SQL Chapter 4 [2 of 2] Phase 1 of Student Projects SQL Data Types & Schemas Authorization.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
SCUHolliday - coen 1788–1 Schedule Today u Modifications, Schemas, Views. u Read Sections (except and 6.6.6) Next u Constraints. u Read.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
Chapter 8: SQL. Data Definition Modification of the Database Basic Query Structure Aggregate Functions.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Advanced Database CS-426 Week 1 - Introduction. Database Management System DBMS contains information about a particular enterprise Collection of interrelated.
CS3431-B111 The Relational Model Instructor: Mohamed Eltabakh
CS 338The Relational Model2-1 The Relational Model Lecture Topics Overview of SQL Underlying relational model Relational database structure SQL DDL and.
Sql DDL queries CS 260 Database Systems.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
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.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 4: Intermediate.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 4: Intermediate.
©Silberschatz, Korth and Sudarshan6.1Database System Concepts Chapter 6: Integrity Constraints Domain Constraints Referential Integrity Assertions Triggers.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Managing Tables, Data Integrity, Constraints by Adrienne Watt
CS 480: Database Systems Lecture 13 February 13,2013.
Chapter 3: SQL.
Instructor: Mohamed Eltabakh
SQL OVERVIEW DEFINING A SCHEMA
Defining a Database Schema
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Instructor: Mohamed Eltabakh
Session - 6 Sequence - 1 SQL: The Structured Query Language:
SQL (Structured Query Language)
Presentation transcript:

©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints

©Silberschatz, Korth and Sudarshan2 Data Definition Language (DDL) DDL allows the specification of a set of relations, i.e., tables. For each table a DDL statement specifies:  A name for the table  A name for each attribute  The domain (i.e., a type) of values associated with each attribute  Integrity constraints  An associated set of indices  Security and authorization information  The physical storage structure for the relation

©Silberschatz, Korth and Sudarshan3 Domain Types in SQL Standard SQL Types:  varchar(n)- Variable length character string, maximum length n.  char(n)- Fixed length character string, with length n.  int- Integer (machine-dependent).  smallint- Small integer (machine-dependent).  real- Floating point numbers machine-dependent precision.  double precision - Floating point numbers machine-dependent precision.  float(n)- Floating point number, precision of at least n digits.  numeric(p,d)- Fixed point number; p digits of precision and d digits to the right of decimal point.

©Silberschatz, Korth and Sudarshan4 Date/Time Types in SQL (Cont.) More complex types are also supported:  date- Dates, containing a year, month and date  time- Time of day, in hours, minutes and seconds  timestamp- Date plus time of day  interval- Period of time  text, BLOB, CLOB, image, geometry, etc. Operations on complex types: (typical)  Interval values can be added/subtracted to or from a date/time/timestamp value  Values of individual fields can be extracted from date/time/timestamp: extract (year from student.birth-date)

©Silberschatz, Korth and Sudarshan5 Create Table Construct An table is defined using the create table command: create table r (A 1 D 1, A 2 D 2,..., A n D n, (integrity-constraint 1 ),..., (integrity-constraint k ))  r is the name of the table  A i is an attribute name  D i is a data type Example: create table branch (branch-namevarchar(16), branch-cityvarchar(32), assetsnumeric(12,2))

©Silberschatz, Korth and Sudarshan6 Integrity Constraints in Create Table Integrity constraints:  not null  primary key (A 1,..., A n )- - Also enforces not null  check (P), where P is a predicate Example: create table branch (branch-namevarchar(16), branch-cityvarchar(32)not null, assetsnumeric(12,2), primary key (branch-name), check (assets >= 0))

©Silberschatz, Korth and Sudarshan7 Referential Integrity in SQL Key types:  primary key - attributes in the primary key.  unique key – attributes in a (non-primary) candidate key.  foreign key - attributes in a foreign key and the name of the relation referenced by the foreign key. A foreign key references the primary key of the referenced table: foreign key (account-number) references account Reference columns can be explicitly specified: foreign key (account-number) references account(account-number) Foreign key references have several implications for insertions, deletions and modifications…

©Silberschatz, Korth and Sudarshan8 DDL Files A DDL file typically contains a collection of:  create table statements  create index statements  statements that create and/or specify other things: Security and authority information Physical storage details A DDL file can be coded by hand, or generated by a schema design or modeling tool.

©Silberschatz, Korth and Sudarshan9 Referential Integrity in SQL – Example create database bankdb; use bankdb; create table customer (customer-name varchar(32), customer-street varchar(32), customer-cityvarchar(16), primary key (customer-name)); create table branch (branch-namevarchar(16), branch-cityvarchar(16), assetsnumeric(12,2), primary key (branch-name)); create table account (account-numberchar(10),*Note tables must be created/loaded/deleted in “foreign key” order branch-namevarchar(16), balancenumeric(9,2), primary key (account-number), foreign key (branch-name) references branch); create table depositor (customer-namevarchar(32), account-numberchar(10), primary key (customer-name, account-number), foreign key (account-number) references account, foreign key (customer-name) references customer); -- Similarly for loan and borrower.

©Silberschatz, Korth and Sudarshan10 Cascading Actions in SQL A foreign key reference can be enhanced to prevent insertion, deletion, and update errors. create table account (... foreign key(branch-name) references branch on delete cascade on update cascade... ) If a delete of a tuple in branch results in a referential-integrity constraint violation, the delete “cascades” to the account relation. Cascading updates are similar.

©Silberschatz, Korth and Sudarshan11 Drop and Alter Table Constructs drop table - deletes all information about a table. drop table customer alter table - used to add or delete attributes to an existing relation. alter table r add A D// Attribute A and domain D alter table r drop A// Attribute A More generally, the alter table command can be used to modify an existing table in many ways, such as adding indexes, changing permissions, storage properties, etc. DO NOT USE THE ALTER COMMAND ON THE PROJECT!!!

©Silberschatz, Korth and Sudarshan12 Drop and Alter Table Constructs Oh, and did I mention… DO NOT USE THE ALTER COMMAND ON THE PROJECT!!!