SQL Overview Defining a Schema CPSC 315 – Programming Studio Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch Via Yoonsuck Choe.

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 5 6_ SQL SQL Is: Structured Query Language
Database Modifications, Data Types, Views. Database Modifications A modification command does not return a result as a query does, but it changes the.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 28 Database Systems I The Relational Data Model.
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.
Fall 2001Arthur Keller – CS 1808–1 Schedule Today Oct. 18 (TH) Schemas, Views. u Read Sections u Project Part 3 extended to Oct. 23 (T). Oct.
SQL Queries CPSC 315 – Programming Studio Spring 2008 Project 1, Lecture 4 Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch.
Winter 2002Arthur Keller – CS 1808–1 Schedule Today: Jan. 29 (T) u Modifications, Schemas, Views. u Read Sections Assignment 3 due. Jan. 31 (TH)
Database Modifications A modification command does not return a result as a query does, but it changes the database in some way. There are three kinds.
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 Relational Data Model CS 157B Nidhi Patel. 2 What is a Data Model? A notation for describing data or information A notation for describing data or information.
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
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
CSE314 Database Systems Lecture 4 Basic SQL Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
CSCE 520- Relational Data Model Lecture 2. Relational Data Model The following slides are reused by the permission of the author, J. Ullman, from the.
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.
Winter 2006Keller Ullman Cushing8–1 Turning in Assignments Please turn in hard copy (use only in the direst of circumstances). I am not your secretary.
CSC 2720 Building Web Applications Database and SQL.
SQL Data Definition Language (DDL) Using Microsoft SQL Server 1SDL Data Definition Language (DDL)
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
BTM 382 Database Management Chapter 7 Introduction to Structured Query Language (SQL) Chitu Okoli Associate Professor in Business Technology Management.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
SCUHolliday - coen 1788–1 Schedule Today u Modifications, Schemas, Views. u Read Sections (except and 6.6.6) Next u Constraints. u Read.
© 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.
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.
CS 338The Relational Model2-1 The Relational Model Lecture Topics Overview of SQL Underlying relational model Relational database structure SQL DDL and.
CSCE 520- Relational Data Model Lecture 2. Oracle login Login from the linux lab or ssh to one of the linux servers using your cse username and password.
1 CSCE Database Systems Anxiao (Andrew) Jiang The Database Language SQL.
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.
SQL Overview Structured Query Language
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Databases : SQL-Schema Definition and View 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey.
SQL Overview CPSC 315 – Programming Studio Spring 2013 Project 1, Part 3 Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch.
Lecture # 24 Introduction to SQL Muhammad Emran Database Systems.
Understand Data Definition Language (DDL) Database Administration Fundamentals LESSON 1.4.
1 Designing Tables for a Database System. 2 Where we were, and where we’re going The Entity-Relationship model: Used to model the world The Relational.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
CPSC-310 Database Systems
Insert, Update and the rest…
Database Models Relational Model
Instructor: Mohamed Eltabakh
SQL OVERVIEW DEFINING A SCHEMA
Defining a Database Schema
CSCE 315 – Programming Studio Spring 2010 Project 1, Lecture 4
CMPT 354: Database System I
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
ISC321 Database Systems I Chapter 4: SQL: Data definition, Constraints, and Basic Queries and Updates Fall 2015 Dr. Abdullah Almutairi.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Instructor: SAMIA ARSHAD
CMSC-461 Database Management Systems
CPSC 315 – Programming Studio Spring 2017 Project 1, Part 3
CSCE 315, Spring 2019 Project 1, Part 3 Robert Lightfoot
SQL (Structured Query Language)
Presentation transcript:

SQL Overview Defining a Schema CPSC 315 – Programming Studio Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch Via Yoonsuck Choe

SQL Structured Query Language Database language used to manage and query relational databases A well-known, commonly used standard  Regularly updated Many extensions, variations  Platform-specific versions, etc.

Generations of Programming Languages 1 st generation  Machine code 2 nd generation  Human-readable but directly related to processor  Assembly language, C (sort of) 3 rd generation  Abstraction from processor, easier for humans  Fortran, C/C++, Java, etc. 4 th generation  Programming Language for specific task  e.g. SQL, Matlab 5 th generation  Give constraints (goal), and result follows logically  e.g. Prolog

SQL Elements Data Definition Language (DDL)  Supports creation of database schema Data Manipulation Language (DML)  Supports entering/removing data Querying Language  Supports query operations (don’t change data itself) Others:  Transaction control, Data control

Our Discussion of SQL Will highlight some of the structures and features of SQL Give you an idea of the basics of how it works  Reflects how relational databases work  Not meant to make you SQL programmers You will need to implement equivalent functions for parts of what we discuss

Database Schema The set of relations (tables) in the database. Create, delete, change tables

CREATE Define a relation CREATE TABLE ( ); element =

Element Types INT, INTEGER  Integers FLOAT, REAL  Floating-Point numbers CHAR(n)  Fixed-length string of n characters VARCHAR(n)  Variable-length string of up to n characters DATE  yyyy-mm-dd TIME  hh:mm:ss

Example CREATE TABLE HouseRep ( Name VARCHAR(80), Party CHAR(10), Birthdate DATE, YearsInCongress INT, Salary REAL );

Declaring Keys Keys declared within CREATE statement Key attributes functionally determine all other attributes in the relation List under PRIMARY KEY  Elements of primary key can not be NULL

Example CREATE TABLE HouseRep ( Name VARCHAR(80), Party CHAR(10), Birthdate DATE, YearsInCongress INT, Salary REAL, PRIMARY KEY (Name) );

Example CREATE TABLE HouseRep ( Name VARCHAR(80), Party CHAR(10), Birthdate DATE, YearsInCongress INT, Salary REAL, PRIMARY KEY (Name, Birthdate) );

Other Element Modifiers UNIQUE  Placed after type  Only one tuple in that relation for each value (except NULL)  Can imply key if no primary key given  Can be NULL NOT NULL  Cannot take value NULL DEFAULT  Default value specified

Example CREATE TABLE HouseRep ( Name VARCHAR(80) UNIQUE, Party CHAR(10), Birthdate DATE NOT NULL, YearsInCongress INT DEFAULT 0, Salary REAL DEFAULT );

Other Table Modifications DROP  Deletes that table ALTER TABLE ADD  Adds a new column to table ALTER TABLE DROP  Removes the column from the table

Other Table Modifications DROP  Deletes that table ALTER TABLE ADD  Adds a new column to table ALTER TABLE DROP  Removes the column from the table

Views Views are a sort of “virtual table”, usually created as the result of a query  We’ll discuss queries soon Format: CREATE VIEW AS

Modifying the Database Data Manipulation Language Given a schema, must “populate” the database with actual data Insert, Delete, Modify

Insertion INSERT command: INSERT INTO VALUES ( ); Can specify only certain attributes in Relation Relation( ) Instead of values, can have subquery

Insertion Example Senator(Name,Party,State,Years) INSERT INTO Senator VALUES (Jill Smith, Republican, NY, 5); INSERT INTO Senator(Name, State) VALUES (Jill Smith, NY);

Deletion Delete from relation according to condition DELETE FROM WHERE ; Example: delete Texas Senators: DELETE FROM Senator WHERE State = ‘TX’;

Modification Update subset according to condition UPDATE SET WHERE ; Example: Joe Lieberman becomes Independent UPDATE Senator SET Party = ‘Independent’ WHERE Name = ‘Joseph Lieberman’;