ZEIT2301 Design of Information Systems SQL: Creating a Database School of Engineering and Information Technology Dr Kathryn Merrick.

Slides:



Advertisements
Similar presentations
Data Definition and Integrity Constraints
Advertisements

MySQL. To start go to Login details: login: labuser password:macimd15 – There.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Maintenance Modifying the data –Add records –Delete records –Update records Modifying the design –Add fields into tables –Remove fields from a table –Change.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
Introduction to Structured Query Language (SQL)
Relational Model Stores data as tables –Each column contains values about the same attribute –Each column has a distinct name –Each row contains values.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
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.
5 Chapter 5 Structured Query Language (SQL1) Revision.
Introduction to Structured Query Language (SQL)
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-1 David M. Kroenke Database Processing Chapter 7 Structured Query Language.
The Relational Model Codd (1970): based on set theory Relational model: represents the database as a collection of relations (a table of values --> file)
ZEIT2301- Database Design Normalisation School of Engineering and Information Technology Dr Kathryn Merrick Bldg 16, Rm 212 (Thursdays and Fridays.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
1 CSE 480: Database Systems Lecture 9: SQL-DDL Reference: Read Chapter of the textbook.
Oracle Data Definition Language (DDL)
Copyright © Curt Hill SQL The Data Definition Language.
Database Design lecture 3_1 1 Database Design Lecture 3_1 Data definition in SQL.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
2440: 141 Web Site Administration Database Management Using SQL Professor: Enoch E. Damson.
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.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
Fundamentals, Design, and Implementation, 9/e CPE 481 Database Processing Chapter 6 Structured Query Language (SQL) Instructor:Suthep Madarasmi, Ph.D.
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.
Chapter 5: Part 1: DDL STRUCTURED QUERY LANGUAGE (SQL)
ZEIT2301 Design of Information Systems SQL: Computing Statistics School of Engineering and Information Technology Dr Kathryn Merrick.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Recap of SQL Lab no 8 Advance Database Management System.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
© 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.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Chapter 7 SQL: Data Definition Pearson Education © 2009.
Visual Programing SQL Overview Section 1.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
Lecture5: SQL Overview, Oracle Data Type, DDL and Constraints Ref. Chapter6 Lecture4 1.
SQL CREATING AND MANAGING TABLES lecture4 1. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically.
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
1 CS 430 Database Theory Winter 2005 Lecture 10: Introduction to SQL.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Chapter 3: Relational Databases
Lecture 03 Constraints. Example Schema CONSTRAINTS.
1 DBS201: More on SQL Lecture 2. 2 Agenda Select command review How to create a table How to insert data into a table.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
CDT/1 Creating data tables and Referential Integrity Objective –To learn about the data constraints supported by SQL2 –To be able to relate tables together.
CompSci 280 S Introduction to Software Development
Tables & Relationships
SQL: Schema Definition and Constraints Chapter 6 week 6
Insert, Update and the rest…
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
ORACLE SQL Developer & SQLPLUS Statements
STRUCTURED QUERY LANGUAGE
Lecturer: Mukhtar Mohamed Ali “Hakaale”
CS4222 Principles of Database System
CS122 Using Relational Databases and SQL
Session - 6 Sequence - 1 SQL: The Structured Query Language:
CS122 Using Relational Databases and SQL
Session - 6 Sequence - 1 SQL: The Structured Query Language:
SQL (Structured Query Language)
Presentation transcript:

ZEIT2301 Design of Information Systems SQL: Creating a Database School of Engineering and Information Technology Dr Kathryn Merrick

Topic 10: SQL Basics This lecture will introduce the SQL for Creating a database Inserting data Updating data Making simple queries We will then compare how this is done in MS Access When can SQL be used? When is it hidden?

Structured Query Language SQL, the “Structured Query Language”, has become the standard language for data manipulation in relational databases SQL is a non-procedural language - it specifies what is to be done, not how it is to be done Relatively easy to use for simple queries some subtleties in more complex queries

4 Statements in SQL’s Data Manipulation Language INSERT – add data to a table UPDATE – modify data in a table DELETE – remove data from a table SELECT – retrieve data from database most commonly used statement (next lecture)

Remember our bike example in 3NF Bike name* Number of riders* Centre of mass height Harley Harley Honda Honda Road conditions* Coefficient of friction Icy0.1 Wet0.5 Dry0.9 Scenario ID* Bike name Number of riders Road conditions Can stoppie 1Harley1Dryfalse 2Harley2Dryfalse 3Honda1Drytrue 4Honda2Drytrue Bike name*Wheelbase Harley1.588 Honda1.458

Creating Relations: Example 1 CREATE TABLE Bikes (bikeName VARCHAR(60) NOT NULL UNIQUE, wheelbase DECIMAL(4, 3) NOT NULL, PRIMARY KEY (bikeName));

Common SQL Data Types Data TypeDescription INTEGERUp to 11 digits; –ve sign takes one place. SMALLINTUp to 6 digits, including sign. NUMERIC(s,d)Fractional numbers, with a maximum of s digits and d decimal places; d can be omitted. DECIMAL(s,d)Fractional numbers, with a minimum of s digits and d decimal places; d and s can be omitted. CHAR(s)Character strings, with s places provided. VARCHAR(s)Unpadded character strings, up to length s. DATETen character date representation (year month day) as digits. BOOLEANBoolean

Creating Relations: Example 2 CREATE TABLE CoMHeight(bikeName VARCHAR(60) NOT NULL UNIQUE, numRiders INTEGER NOT NULL comHeight DECIMAL(4, 3) NOT NULL, CONSTRAINT pk2 PRIMARY KEY (bikeName) CONSTRAINT fk1 FOREIGN KEY (bikeName) REFERENCES Bikes ON UPDATE CASCADE ON DELETE NO ACTION);

SQL Constraints Constraint TypeDescription CONSTRAINT… PRIMARY KEY… Supports entity integrity. Defines the primary key column(s). Must be NOT NULL and UNIQUE CONSTRAINT…FOREIGN KEY… ON UPDATE … ON DELETE… Supports referential integrity Regulates update/delete operations that have implications to other relations Foreign Key Subclause Values CASCADEUpdate/delete rows from parent table and automatically update/delete matching rows in child tables SET NULLUpdate/delete rows from parent table and set the foreign key values in child table to NULL NO ACTIONReject the update/delete operation

Inserting Records into a Relation INSERT INTO Bikes VALUES (‘Harley’, 1.588); INSERT INTO Bikes VALUES (‘Honda’, 1.458); INSERT INTO Bikes VALUES(‘Mongoose Expert’, 0.932); INSERT INTO CoMHeight VALUES(‘Harley’, 0, 0.724);

Inserting Records From a File It may not be practical to write insert statements for every record To read multiple records from a file in bulk: LOAD DATA LOCAL INFILE filename INTO TABLE Bikes FIELDS TERMINATED BY ‘\t’;

Viewing Records: Simple SELECT SELECT * FROM Bikes; SELECT scenarioID, canStoppie FROM Scenarios; SELECT * FROM CoMHeight WHERE bikeName = ‘Harley’; SELECT * FROM CoMHeight WHERE numRiders > 1;

Modifying Records UPDATE Bikes SET wheelbase = 1.6 WHERE bikeName = ‘Harley’ UPDATE CoMHeight SET comHeight = WHERE bikeName = ‘Harley’ AND numRiders = 1;

Deleting Records DELETE FROM CoMHeight WHERE bikeName = ‘Honda’; DELETE FROM CoMHeight WHERE numRiders = 2;

MS Access

Summary After today’s lecture you should be able to: Create and update a relational database using SQL