Data Definition After this lecture, you should be able to:

Slides:



Advertisements
Similar presentations
SQL: The Query Language Part 1 R &G - Chapter 5 Life is just a bowl of queries. -Anon (not Forrest Gump)
Advertisements

Complex Integrity Constraints in SQL. Constraints over a Single Table Table Constraint: Create TABLE Sailors (sid INTEGER, sname CHAR(10), rating INTEGER,
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra) Query Formulation Exercise.
Database Languages Chapter 7. The Relational Algebra.
Unit 5 The Network Model  5.1 The Network Model  5.2 IDMS.
1 Advanced SQL Queries. 2 Example Tables Used Reserves sidbidday /10/04 11/12/04 Sailors sidsnameratingage Dustin Lubber Rusty.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
1 Lecture 11: Basic SQL, Integrity constraints
Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands.
Cs3431 Constraints Sections 6.1 – 6.5. cs3431 Example CREATE TABLE Student ( sNum int, sName varchar (20), prof int, CONSTRAINT pk PRIMARY KEY (snum),
Representing Data Elements Gayatri Gopalakrishnan.
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.
1 SQL (Simple Query Language). 2 Query Components A query can contain the following clauses –select –from –where –group by –having –order by Only select.
Winter 2002Arthur Keller – CS 1808–1 Schedule Today: Jan. 29 (T) u Modifications, Schemas, Views. u Read Sections Assignment 3 due. Jan. 31 (TH)
Basic SQL types String –Char(n): fixed length. Padded –Varchar(n): variable length Number –Integer: 32 bit –Decimal(5,2): –Real, Double: 32 bit,
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.
1 The Oracle Database System Querying the Data Database Course The Hebrew University of Jerusalem.
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.
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.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
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,
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch Via Yoonsuck Choe.
Data Manipulation 11 After this lecture, you should be able to:  Understand the differences between SQL (Structured Query Language) and other programming.
6.8 Case Study: E-R for Supplier-and-Parts Database
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 8 Part 1 SQL-99 Schema Definition, Constraints, Queries, and Views.
4B-1 Wei-Pang Yang, Information Management, NDHU Introduction to Database CHAPTER 4B ( 補 ) DB2 and SQL  Overview  Data Definition  Data Manipulation.
Logical Database Design ( 補 ) Unit 7 Logical Database Design ( 補 )
CSC 2720 Building Web Applications Database and SQL.
Chapter 10 Views. Topics in this Chapter What are Views For? View Retrievals View Updates Snapshots SQL Facilities.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
ICS 321 Fall 2009 SQL: Queries, Constraints, Triggers Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 9/8/20091Lipyeow.
SCUHolliday - coen 1788–1 Schedule Today u Modifications, Schemas, Views. u Read Sections (except and 6.6.6) Next u Constraints. u Read.
Data Manipulation 21 After this lecture, you should be able to:  Use SQL SELECT statement effectively to retrieve the data from multiple related tables.
Unit 5 The Network Model  5.1 Data Modeling Issues  5.2 The Network Model  5.3 IDMS.
Algebra1 After this lecture, you should be able to:  Understand the differences between SQL (Structured Query Language) and Relational Algebra expressions.
The Oracle Database System. Connecting to the Database At the command line prompt, write: sqlplus In the beginning your password.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
Perform DFS from A A B C D E F G. Perform BFS from A A B C D E F G.
An Introduction to SQL For CS Overview of SQL  It is the standard language for relational systems, although imperfect  Supports data definition.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
Unit 2 DB2 and SQL. 2-2 Wei-Pang Yang, Information Management, NDHU Outline of Unit Overview 2.2 Data Definition 2.3 Data Manipulation 2.4 The System.
There are two types of MySQL instructions (Data Definition Language) DDL: Create database, create table, alter table,,,. (Data Manipulation Language) DML.
CSCI 4333 Database Design and Implementation – Exercise (2) Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
SQL: The Query Language Part 1 R &G - Chapter 5 The important thing is not to stop questioning. Albert Einstein.
Spring 2011 ITCS3160: Database Design and Implementation Hands-on Learning.
Views Prof. Yin-Fu Huang CSIE, NYUST Chapter 10. Advanced Database System Yin-Fu Huang 10.1Introduction Example: Var Good_Supplier View (S Where Status.
8 Copyright © 2005, Oracle. All rights reserved. Managing Schema Objects.
Structured Query Language IV Asma Ahmad (C. J. Date) Database Systems.
STRUCTURE OF PRESENTATION :
CS 3630 Database Design and Implementation
Lecture 3 : Structured Query Language (SQL)
Unit 2 DB2 and SQL.
Introduction to Database
Introduction to Database
CS 405G: Introduction to Database Systems
CSCI 6315 Applied Database Systems – Exercise (3)
SQL OVERVIEW DEFINING A SCHEMA
پايگاه داده ها.
SQL: The Query Language Part 1
Φροντιστήριο SQL (από το βιβλίο του Date)
Unit 7 Normalization (表格正規化).
Session - 6 Sequence - 1 SQL: The Structured Query Language:
STRUCTURE OF PRESENTATION :
CMSC-461 Database Management Systems
STRUCTURE OF PRESENTATION :
SQL (Structured Query Language)
Presentation transcript:

Data Definition After this lecture, you should be able to: Use SQL DDL Statement to define a database structure. Work with mysql or phpMyAdmin to access your MySQL databases. Complete Assignment 2 (Part II - a, b). 1

SQL DDL Statements Create Table create table s (sno char(5), ... ); Drop Table drop table s; Alter Table alter table s add phone char(13); Create View create view SV as select .... Drop View drop view SV; Create Index create index X on s(sno); Drop Index drop index X;

Suppliers-Parts Database: E-R Diagram sno (key) pno (key) sname pname SP M S M P city status city qty color weight

Supplier-Part Database Table S Table P sno | sname | status | city pno | pname | color | weight | city ------------------------------ ---------------------------------- s1 | Smith | 20 | London p1 | nut | red | 12 | London s2 | Jones | 10 | Paris p2 | bolt | green | 17 | Paris s3 | Blake | 30 | Paris p3 | screw | blue | 17 | Rome s4 | Clark | 20 | London p4 | screw | red | 14 | London s5 | Adams | 30 | Athens p5 | cam | blue | 12 | Paris p6 | cog | red | 19 | London Table SP sno | pno | qty --------------- s1 | p1 | 300 s1 | p2 | 200 s1 | p3 | 400 s1 | p4 | 200 s1 | p5 | 100 s1 | p6 | 100 s2 | p1 | 300 s2 | p2 | 400 s3 | p2 | 200 s4 | p2 | 200 s4 | p4 | 300 s4 | p5 | 400

Create Table Statements sno char(5) not null, sname char(20) not null, status smallint, city char(15), primary key (sno) ); create table p ( pno char(6) not null, pname char(20) not null, color char(6), weight smallint, primary key (pno) create table sp ( qty integer not null, primary key (sno, pno)

Data Types integer The magnitude range is -2,147,484,648 ... +2,147,484,647. real For fixed or floating-point numbers. Allowable values are -3.402823466E+38 to -1.175494351E-38, 0, and 1.175494351E-38 to 3.402823466E+38. char For fixed length character strings up to 255 bytes. varchar For variable-length character strings. The maximum length is 65,532 bytes. bit[n] n indicates the number of bits, from 1 to 64. The default is 1 if n is omitted . date Year values in the range 70-99 are converted to 1970-1999. Year values in the range 00-69 are converted to 2000-2069. datetime Date and time. The format is ‘YYYY-MM-DD HH:MM:SS’.

Creating S-P-SP Database % mysql –h mysql.cs.orst.edu –u pham –p pham Enter password: mysql> \. create_s_p_sp.sql; Query OK, 0 rows affected (0.01 sec) SQL> show tables; TABLE_in_pham ----------------- p s sp

Looking at Table Structures mysql> desc s; Name Null? Type ---------- -------- ---- SNO NOT NULL CHAR(5) SNAME NOT NULL CHAR(20) STATUS SMALLINT(6) CITY CHAR(15) mysql> desc p; Name Null? Type PNO NOT NULL CHAR(6) PNAME NOT NULL CHAR(20) COLOR CHAR(6) WEIGHT SMALLINT(6)

Adding Data to a Table insert into s values('s1', 'Smith', 20, 'London'); values('s2', 'Jones', 10, 'Paris'); values('s3', 'Blake', 30, 'Paris'); values('s4', 'Clark', 20, 'London'); values('s5', 'Adams', 30, 'Athens'); mysql> \. insert_s_p_sp.sql Query OK, 0 rows affected (0.01 sec) . . .

Showing Table Contents SQL> select * from s; SNO SNAME STATUS CITY ---- ------- -------- ------ s1 Smith 20 London s2 Jones 10 Paris s3 Blake 30 Paris s4 Clark 20 London s5 Adams 30 Athens SQL> select * from p; PNO PNAME COLOR WEIGHT CITY ----- ------- ------- -------- ------- p1 nut red 12 London p2 bolt green 17 Paris p3 screw blue 17 Rome p4 screw red 14 London p5 cam blue 12 Paris p6 cog red 19 London

Sailors-Boats Database: E-R Diagram (Schema) sid (key) sname bid (key) bname Reserves Sailor M M Boat date rating age color 4

Create Table Statements create table sailors ( sid integer not null, sname char(20) not null, rating smallint, age real, primary key (sid) ); create table boats ( bid integer not null, bname char(20) not null, color char(10), primary key (bid) create table reserves ( sid integer not null, day date not null, primary key (sid, bid, day)

Sailors-Boats Database: Tables sid sname rating age 22 Dustin 7 45.0 33 Libber 8 55.5 Boats bid bname color 2 Yuppy Blue 3 Lubber Red Reserves sid bid day 22 2 10/10/96 3 10/09/96 33 11/12/96