CS 104 Introduction to Computer Science and Graphics Problems Introduction to Database (2) Basic SQL 12/05/2008 Yang Song.

Slides:



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

OUTLINE OF THE LECTURE PART I GOAL: Understand the Data Definition Statements in Fig 4.1 Step1: Columns of the Tables and Data types. Step2: Single column.
Basic Queries. 2 Retrieval Queries in SQL SQL has one basic statement for retrieving information from a database; the SELECT statement This is not the.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
SQL Query Slides Sharif University Of Technology Database Systems CE 384 Prepared By: Babak Bagheri Hariri
Displaying Data from Multiple Tables. EMPNO DEPTNO LOC NEW YORK CHICAGO NEW YORK DALLAS
Database technology Lecture 2: Relational databases and SQL
Data Definition Languages Atif Farid Mohammad UNCC.
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
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 8- 1.
1 CSE 480: Database Systems Lecture 10: SQL - DML Reference: Read Chapter 4 of the textbook.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 SQL: Data Definition, Constraints, and Basic Queries and Updates.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 SQL-99: SchemaDefinition, Constraints, and Queries and Views.
SQL SQL stands for Structured Query Language SQL allows you to access a database SQL is an ANSI standard computer language SQL can execute queries against.
DML- Insert. DML Insert Update Delete select The INSERT INTO Statement The INSERT INTO statement is used to insert new rows into a table. Syntax INSERT.
관계 연산자 & SQL. Selection SELECT * FROM r WHERE A=B AND D>5.
SQL The relational DB Standard CS-450 Dr. Ali Obaidi.
Advanced Database CS-426 Week 2 – Logic Query Languages, Object Model.
Al-Imam University Girls Education Center Collage of Computer Science 1 ST Semester, 1432/1433H Chapter 8 Part 4 SQL-99 Schema Definition, Constraints,
CSE314 Database Systems Lecture 4 Basic SQL Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
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.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
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.
1 CS 430 Database Theory Winter 2005 Lecture 12: SQL DML - SELECT.
1 CSE 480: Database Systems Lecture 11: SQL. 2 SQL Query SELECT FROM WHERE –In MySQL, FROM and WHERE clauses are optional –Example:
Onsdag The concepts in a relation data model SQL DDL DML.
 Employee (fname, minit, lname, ssn, bdate, address, sex, salary, superssn, dno)  Department (dname, dnumber, mgrssn, mgrstartdate) 
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
DatabaseDatabase cs453 Lab5 1 Ins.Ebtesam AL-Etowi.
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.
Visual Programing SQL Overview Section 1.
Structured Query Language
CMPT 258 Database Systems The Relationship Model (Chapter 3)
1 Database Systems Basic SQL. 2Outline  SQL Data Definition and Data Types  Specifying Constraints in SQL  Basic Retrieval Queries in SQL  INSERT,
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 20 A First Course in Database Systems.
الفصل السادس لغة Structured Query Language) SQL الفصل السادس لغة Structured Query Language) SQL.
1 COMP 1100 Basic SQL David J. Stucki. Outline SQL Overview Retrievals Schema creation Table creation Constraints Inserts Updates 2.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
Introduction to Database Programming with Python Gary Stewart
Big Data Yuan Xue CS 292 Special topics on.
CS580 Advanced Database Topics Chapter 8 SQL Irena Pevac.
1 Chapter (8) SQL The Relational Database Standard Objectives Presenting the main features of SQL SQL is the Structured Query Language SQL commands SQL.
Chapter 10 SQL DDL.
The SQL Database Grammar
SQL: SchemaDefinition, Constraints, and Queries and Views
Database Systems Basic SQL
Retrieval Queries in SQL(DML)
Subject Name: DATA BASE MANAGEMENT SYSTEM Subject Code: 10cs54
376a. Database Design Dept. of Computer Science Vassar College
376a. Database Design Dept. of Computer Science Vassar College
11/9/2018.
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
CS4222 Principles of Database System
Session - 6 Sequence - 2 SQL: The Structured Query Language:
Chapter 4 Basic SQL. Chapter 4 Basic SQL Chapter 4 Outline Overview of SQL SQL Data Definition (DDL) for Specifying a Relational Database Schema CREATE.
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
SQL-99: Schema Definition, Constraints, and Queries and Views
ISC321 Database Systems I Chapter 4: SQL: Data definition, Constraints, and Basic Queries and Updates Fall 2015 Dr. Abdullah Almutairi.
SQLPLUS: Oracle SQL Interface
Session - 6 Sequence - 1 SQL: The Structured Query Language:
SQL Grouping, Ordering & Arithmetics Presented by: Dr. Samir Tartir
Presentation transcript:

CS 104 Introduction to Computer Science and Graphics Problems Introduction to Database (2) Basic SQL 12/05/2008 Yang Song

What is SQL SQL = Structured Query Language. SQL is a comprehensive database language. It has statements for data definition, query and update. SQL became a standard for relational databases in 1986, a revised and more extended version became a standard in 1992, A new version of the standard extends SQL with object-oriented and other recent database concepts. The SQL language provides a high-level declarative language interface: the user specifies what the result is to be and leaves the decisions on how to execute the query to the DBMS.

Basic SQL The terms table, row and column are used in SQL documents for relation, tuple and attribute respectively. The data types available for attribute values include numeric, character-string, bit-string, date and time. Numeric INTEGER FLOAT Character String CHARACTER(n) Bit String BIT(n) Date and Time DATE: yyyy-mm-dd TIME: hh:mm:ss

Create Table The CREATE TABLE command is used to specify a new relation, its attributes, their data type and constraints. The format is: CREATE TABLE tablename ( column name1 datatype1, column name2 datatype2, …… PRIMARY KEY (column name), FOREIGN KEY (column name) REFERENCES tablename (column name) ……..); To add the new records, use INSERT: The format is: INSERT INTO tablename VALUES (value1, value2….);

Create Table (example) To create a table for students, which records students’ name, student ID, sex, grade and birth date, and use student ID as the primary key. CREATE TABLE student (Name VARCHAR(10), ID CHAR(8), Sex CHAR(1), Grade CHAR(1), BDate DATE, PRIMARY KEY (ID)); To insert a student with name “John Smith”, ID number , male, grade as B and born in Jan.1 st, 1988: INSERT INTO student VALUES (‘John Smith’, ‘ ’, ‘M’, ‘B’, ‘ ’);

Basic Queries SQL has one basic statement for retrieving information from a database; the SELECT statement Basic form of the SQL SELECT statement (also called SELECT-FROM-WHERE block): SELECT FROM WHERE is a list of attribute names whose values are to be retrieved by the query is a list of the relation names required to process the query is a conditional (Boolean) expression that identifies the tuples to be retrieved by the query So a SELECT-FROM-WHERE block is formed of the three clauses: SELECT, FROM, WHERE

Basic Queries (examples) A query gets involved with one relation. If the relation schema is: EMPLOYEE{Fname, Lname, Minit, Bdate, Address, DNo, SSN} Query: Retrieve the birth date and address of the employee whose name is ‘John B. Smith’. SQL: SELECT Bdate, Address FROM EMPLOYEE WHERE Fname=‘John’ AND Minit=‘B’ AND Lname=‘Smith’;

Basic Queries (examples) A query gets involved with two relation. Two relations schema are: EMPLOYEE{Fname, Lname, Minit, Bdate, Address, DNo, SSN} DEPARTMENT{Dname, Location, DNo} Query: Retrieve the name and address of all employees who work for the 'Research’ department. SQL: SELECT Fname, Lname, Address FROM EMPLOYEE, DEPARTMENT WHERE Dname = ‘Research’ AND EMPLOYEE.DNo=DEPARTMENT.DNo;

Basic Queries (examples) Some queries need to refer to the same relation twice. If the given relation schema is EMPLOYEE{Fname, Lname, SSN, SUPERSSN} where the SUPERSSN is this employee’s supervisor’s SSN. Query: For each employee, retrieve the employee’s name, and the name of his or her immediate supervisor. SQL: SELECT E.Fname, E.Lname, S.Fname, S.Lname FROM EMPLOYEE AS E, EMPLOYEE AS S WHERE E.SUPERSSN = S.SSN;

Basic Queries (examples) A missing WHERE clause indicates no condition, that is, all tuples of the relations in the FROM clause are selected. Query: Retrieve the SSN values of all the employees. SQL: SELECT SSN FROM EMPLOYEE