Session - 6 Sequence - 1 SQL: The Structured Query Language:

Slides:



Advertisements
Similar presentations
Fundamentals of Database Systems Fourth Edition El Masri & Navathe
Advertisements

MySQL. To start go to Login details: login: labuser password:macimd15 – There.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Fall 2005 ICS184/EECS116 – Notes 08 1 ICS 184/EECS116: Introduction to Data Management Lecture Note 8 SQL: Structured Query Language -- DDL.
Overview Begin 6:00 Quiz15 mins6:15 Review Table Terms25 mins6:40 Short Break10 mins6:50 SQL: Creating Tables60 mins7:50 Break10 mins8:00 Lab – Creating.
Database Design -- Basic SQL
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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 SQL: Data Definition, Constraints, and Basic Queries and Updates.
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.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
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.
1 CSE 480: Database Systems Lecture 9: SQL-DDL Reference: Read Chapter of the textbook.
Oracle Data Definition Language (DDL)
SQL Overview Defining a Schema CPSC 315 – Programming Studio Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch Via Yoonsuck Choe.
CSE314 Database Systems Lecture 4 Basic SQL Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 SQL-99: Schema Definition, Constraints, and Queries and Views.
Structured Query Language The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe, Fundamental of Database Systems, 4.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
Chapter 8 Part 1 SQL-99 Schema Definition, Constraints, Queries, and Views.
Ms. Hatoon Al-Sagri CCIS – IS Department SQL-99 :Schema Definition, Constraints, Queries, and Views 1.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
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.
© 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 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.
Chapter 8 Part 2 SQL-99 Schema Definition, Constraints, Queries, and Views.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
DBSQL 5-1 Copyright © Genetic Computer School 2009 Chapter 5 Structured Query Language.
SQL CREATING AND MANAGING TABLES lecture4 1. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E) 1.
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 Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
الفصل السادس لغة Structured Query Language) SQL الفصل السادس لغة Structured Query Language) SQL.
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.
SQL- Updates, Assertions and Views. Data Definition, Constraints, and Schema Changes Used to CREATE, DROP, and ALTER the descriptions of the tables (relations)
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
CPSC-310 Database Systems
Structured Query Language
Chapter 10 SQL DDL.
SQL: SchemaDefinition, Constraints, and Queries and Views
SQL: Schema Definition and Constraints Chapter 6 week 6
Insert, Update and the rest…
CS 480: Database Systems Lecture 13 February 13,2013.
Chapter 4 Basic SQL.
Subject Name: DATA BASE MANAGEMENT SYSTEM Subject Code: 10cs54
Database Models Relational Model
11/9/2018.
ORACLE SQL Developer & SQLPLUS Statements
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
CS4222 Principles of Database System
SQL OVERVIEW DEFINING A SCHEMA
Defining a Database Schema
Oracle Data Definition Language (DDL)
SQL-1 Week 8-9.
SQL-99: Schema Definition, Constraints, and Queries and Views
Chapter # 7 Introduction to Structured Query Language (SQL) Part I.
ISC321 Database Systems I Chapter 4: SQL: Data definition, Constraints, and Basic Queries and Updates Fall 2015 Dr. Abdullah Almutairi.
CS4433 Database Systems Relational Model.
SQL Updating Database Contents Presented by: Dr. Samir Tartir
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Instructor: SAMIA ARSHAD
SQL (Structured Query Language)
Presentation transcript:

Session - 6 Sequence - 1 SQL: The Structured Query Language: Introduction and Tables Presented by: Dr. Samir Tartir

Introduction SQL is the standard for relational databases. It is based on Relational Algebra and Relational Calculus. User-friendly syntax

SQL Scope Schema: Data: Data Access Control creation and modification DDL (Data Definition Language) Data: insert, query, update and delete DML (Data Manipulation Language) Data Access Control DCL (Data Control Language)

SQL Data Types Numeric Character Strings Integers Real numbers INTEGER, and SMALLINT Real numbers FLOAT, REAL, DOUBLE PRECISION Formatted numbers DECIMAL(i,j) or NUMERIC(i,j) Character Strings CHAR(n), VARCHAR(n)

SQL Data Types Date and Time: DATE: TIME: TIME(i): Made up of year-month-day in the format yyyy-mm-dd TIME: Made up of hour:minute:second in the format hh:mm:ss TIME(i): Made up of hour:minute:second plus i additional digits specifying fractions of a second format is hh:mm:ss:ii...i

CREATE TABLE Specifies a new base relation by giving it a name, and specifying each of its attributes and their data types. A constraint NOT NULL may be specified on an attribute

Example CREATE TABLE DEPARTMENT ( DNAME VARCHAR(10) NOT NULL, Table Name CREATE TABLE DEPARTMENT ( DNAME VARCHAR(10) NOT NULL, DNUMBER INTEGER NOT NULL, MGRSSN CHAR(9), MGRSTARTDATE CHAR(9) ); Column Names Column Types Null?

CREATE TABLE Primary key Referential integrity constraints (foreign keys) Key attributes can be specified via the PRIMARY KEY and UNIQUE phrases

Example CREATE TABLE DEPT ( DNAME VARCHAR(10) NOT NULL, DNUMBER INTEGER NOT NULL, MGRSSN CHAR(9), MGRSTARTDATE CHAR(9), PRIMARY KEY (DNUMBER), UNIQUE (DNAME), FOREIGN KEY (MGRSSN) REFERENCES EMP );

ALTER TABLE Used to add an attribute to one of the base relations The new attribute will have NULLs in all the tuples of the relation right after the command is executed; hence, the NOT NULL constraint is not allowed for such an attribute

Example Adding a job description to each employee ALTER TABLE EMPLOYEE ADD JOB VARCHAR(12); The database users must still enter a value for the new attribute JOB for each EMPLOYEE tuple. This can be done using the UPDATE command.

Example Modify the size of the last name field to 50. ALTER TABLE EMPLOYEE MODIFY LNAME VARCHAR(50);

Example Remove the birthdate column from the Employee table. ALTER TABLE EMPLOYEE DROP COLUMN BIRTHDATE;

DROP TABLE Used to remove a relation (base table) and its definition The relation can no longer be used in queries, updates, or any other commands since its description no longer exists Example: DROP TABLE DEPENDENT;

DROP TABLE If a table has other tables connect to (using foreign keys), it can’t be removed until the foreign keys are removed first. Or, using the following statement that removes the table and any foreign key constraints connected to it. Example: DROP TABLE EMPLOYEE CASCADE CONSTRAINTS;