SQL introduction 2013.

Slides:



Advertisements
Similar presentations
Chapter 4 Hotel (hotelno, hotelname, city)
Advertisements

Basic SQL Introduction Presented by: Madhuri Bhogadi.
1 Assignment 2 Relational Algebra Which tables? What operations? Common attributes? What result (attributes)? Syntax (Standard Notations and Symbols) –Product:
1 SQL Server Management Studio SQL DDL CREATE TABLE Constraints ALTER TABLE DROP TABLE The GUI way Steen Jensen, autumn 2013.
CS 3630 Database Design and Implementation. SQL Query Clause Select and From Select * From booking; select hotel_no, guest_no, room_no from booking; select.
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
Chapter 5 SQL Homework.
Using SQL to create tables Ways of using Databases.
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
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.
DT211 Stage 2 Databases Lab 1. Get to know SQL Server SQL server has 2 parts: –A client, running on your machine, in the lab. You access the database.
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
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.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
Database Systems Lecture 5 Natasha Alechina
Introduction to SQL  SQL or sequel  It is a standardised language with thousands of pages in the standard  It can be in database system through GUI,
MY SQL Eng: SAHAR. Introduction to SQL What is SQL? When a user wants to get some information from a database file, he can issue a query A query is a.
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.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
ISM 4212 Lab Creating DB Tables 02 copyright Lars Paul Linden 2007.
SQL Data Definition Language (DDL) Using Microsoft SQL Server 1SDL Data Definition Language (DDL)
Slide 1 Chapter 7 – Part 1 Data Definition Language & Data Manipulation Language.
Chapter 5: Part 1: DDL STRUCTURED QUERY LANGUAGE (SQL)
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.
SQL queries ordering and grouping and joins
SQL - DML. Data Manipulation Language(DML) Are used for managing data: –SELECT retrieve data from the a database –INSERT insert data into a table –UPDATE.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
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.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
SQL Structured Query Language. Aims  To introduce the implementation of a Physical design using SQL.  To introduce SQL Data Definition Language (DDL).
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
1 DBS201: More on SQL Lecture 3. 2 Agenda How to use SQL to update table definitions How to update data in a table How to join tables together.
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.
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
1 CS 430 Database Theory Winter 2005 Lecture 10: Introduction to SQL.
Populating and Querying tables Insert, Update, Delete and View (DML)
There are two types of MySQL instructions (Data Definition Language) DDL: Create database, create table, alter table,,,. (Data Manipulation Language) DML.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
IS6146 Databases for Management Information Systems Lecture 3: SQL III – The DDL Rob Gleasure robgleasure.com.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Chapter 3: Relational Databases
CS 3630 Database Design and Implementation. Base Table and View Base Table Stored on disk View Virtual table Records are not stored on disk Query is stored.
UNIVERSITAS BINA DARMA 2013 DATA DEFINITION LANGUAGE (DDL)
Understand Data Definition Language (DDL) Database Administration Fundamentals LESSON 1.4.
Structured Query Language
CS 3630 Database Design and Implementation
Assignment 2 Relational Algebra Which tables? What operations?
Managing Tables, Data Integrity, Constraints by Adrienne Watt
SQL: Schema Definition and Constraints Chapter 6 week 6
Assignment 2.
CS 3630 Database Design and Implementation
STRUCTURED QUERY LANGUAGE
Structured Query Language (Data definition Language)
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
SQL OVERVIEW DEFINING A SCHEMA
DATABASE SQL= Structure Query Language مبادئ قواعد بيانات
مقدمة في قواعد البيانات
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Data Definition Language
Session - 6 Sequence - 1 SQL: The Structured Query Language:
SQL (Structured Query Language)
Presentation transcript:

SQL introduction 2013

Languages Languages for relational DBMSs are: SQL QBE Structures Query Language QBE Query by example A graphical frontent to SQL Will convert into corresponding SQL

SQL Two main parts: Two ways of using SQL: Data Definition Language (DDL) To define the database structure Data Manipulation Language (DML) For retrieving and updating the data Two ways of using SQL: Interactive Embedded in a procedural language as Java

SQL ISO standard A standard database language There are many versions of SQL Nearly every database is based on SQL Non-procedural language Specify ”What” and not ”How”

Data definition Language(DDL) Statements that are used to define the database structure: CREATE - to create objects in the database ALTER - alters the structure of the database DROP - delete objects from the database We look at create table Can be done through a GUI interface

HotelDB HOTEL: (Hotel_No, Name, Address) ROOM: (Room_No, Hotel_No, Types, Price) BOOKING: ( Hotel_No, Guest_No, Date_From, Date_To, Room_No) GUEST: (Guest_No, Name, Address)

Alternativ HotelDB HOTEL:(Hotel_No, Name, Address) ROOM:(Room_No, Hotel_No, Types, Price) BOOKING:( BookingID, Hotel_No, Guest_No, Date_From, Date_To, Room_No) GUEST:(Guest_No, Name, Address)

Create Database CREATE DATABASE HotelDb Creates a database.

Creating tables Creating a table (simplified): CREATE TABLE Hotel (<field definitions> PRIMARY KEY <field list>) Complete syntax for creating a new table is rather complicated See syntax DB note page 63

Creating tables Each field definition contains The field name The data type for the field Can the field be NULL or not Must the field be unique Does the field have a default value

Create Table Hotel CREATE TABLE Hotel( Hotel_No int IDENTITY(1,1) NOT NULL PRIMARY KEY, Name VARCHAR(30) NOT NULL, Address VARCHAR(50) NOT NULL );

Creating Table Room CREATE TABLE Room( Room_No int NOT NULL, Hotel_No int NOT NULL, Types CHAR(1) DEFAULT 'S', Price FLOAT, CONSTRAINT checkType CHECK (Types IN ('D','F','S') OR Types IS NULL), CONSTRAINT checkPrice CHECK (price BETWEEN 0 AND 9999), FOREIGN KEY (Hotel_No) REFERENCES Hotel (Hotel_No) ON UPDATE CASCADE ON DELETE NO ACTION, Primary KEY (Room_No, Hotel_No) );

Creating table Guest CREATE TABLE Guest ( Guest_No int NOT NULL PRIMARY KEY, Name VARCHAR(30) NOT NULL, Address VARCHAR(50) NOT NULL );

Creating Table Booking CREATE TABLE Booking( Booking_id int IDENTITY(1,1) NOT NULL PRIMARY KEY, Hotel_No int NOT NULL, Guest_No int NOT NULL, Date_From DATE NOT NULL, Date_To DATE NOT NULL, Room_No int NOT NULL, FOREIGN KEY(Guest_No) REFERENCES Guest(Guest_No), FOREIGN KEY(Room_No, Hotel_No) REFERENCES Room(Room_No, Hotel_No) );

Alter Table ok ALTER TABLE Booking ADD CONSTRAINT incorrect_dates CHECK ((Date_To > Date_From) AND (Date_From <= '2014-01-01'));

SQL Server Data Types http://www.w3schools.com/sql/sql_datatypes.asp

Exercise – SQL DDL queries Create a database using the assignment ”HotelDB create” found on the teachers homepage. Create the tables one by one. Use the HotelDB database. Create a new table in the HotelDB database called Facilities, with the following fields: Facility_no identifier Description Create a table Room_Facilities to connect the Room with the Facilities. What is the primary key What is the Foreign key(s)