CS252: Systems Programming Ninghui Li Based on Slides by Gustavo Rodriguez-Rivera Topic 18: SQL and Relational Databases.

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizards Guide to PHP by David Lash.
Advertisements

Structured Query Language (SQL)
Session 2Introduction to Database Technology Data Types and Table Creation.
Creating Tables, Setting Constraints, and Datatypes What is a constraint and why do we use it? What is a datatype? What does CHAR mean? Page 97 in Course.
COMP 3715 Spring 05. Working with data in a DBMS Any database system must allow user to  Define data Relations Attributes Constraints  Manipulate data.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
Quick-and-dirty.  Commands end in a semi-colon ◦ If you forget, another prompt line shows up  Either continue the command or…  End it with a semi-colon.
How to Use MySQL CS430 March 18, SQL: “Structured Query Language”—the most common standardized language used to access databases. SQL has several.
CSE 190: Internet E-Commerce Lecture 10: Data Tier.
Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.
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.
5 Chapter 5 Structured Query Language (SQL1) Revision.
30-Jun-15 SQL A Brief Introduction. SQL SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell”
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
CSC 2720 Building Web Applications Database and SQL.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
Phil Brewster  One of the first steps – identify the proper data types  Decide how data (in columns) should be stored and used.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
CHAPTER 7 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.
Introduction to SQL Steve Perry
Data-mining & Data As we used Excel that has capability to analyze data to find important information, the data-mining helps us to extract information.
CIS 103 — Applied Computer Technology Last Edited: September 17, 2010 by C.Herbert Using Database Management Systems.
Web Services Week 8 Aims: –Using web services as front ends to databases Objectives: –Review of relational databases –Connecting to and querying databases.
PHP and MySQL CS How Web Site Architectures Work  User’s browser sends HTTP request.  The request may be a form where the action is to call PHP.
Database Fred Durao What is a database? A database is any organized collection of data. Some examples of databases you may encounter in.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
Chapter 10: The Data Tier We discuss back-end data storage for Web applications, relational data, and using the MySQL database server for back-end storage.
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.
Most information comes from Chapter 3, MySQL Tutorial: 1 MySQL: Part.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
SQL by Example By convention SQL keywords are written in uppercase. SELECT * FROM Books –This query returns all rows in the Books table. –SQL statements.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall.
Course FAQ’s I do not have any knowledge on SQL concepts or Database Testing. Will this course helps me to get through all the concepts? What kind of.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
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,
THE WEBMASTERS: SENG + WAVERING.  On account of construction, we will be having class in room 1248 next week.
Database Basics BCIS 3680 Enterprise Programming.
SQL has several parts: Major ones: DDL – Data Definition Language {Defining, Deleting, Modifying relation schemas} DML – Data Manipulation Language {Inserting,
BSA206 Database Management Systems Lecture 2: Introduction to Oracle / Overview of Database Concepts.
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
CS 111 – Nov. 8 Databases Database Management Systems (DBMS) Structured Query Language (SQL) Commitment –Please review sections 9.1 – 9.2.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Mysql YUN YEO JOONG. 1 Connecting to and Disconnecting from the Server 1 Connecting to and Disconnecting from the Server shell> mysql – h host -u user.
April 2002 Information Systems Design John Ogden & John Wordsworth 1 Database Design SQL (1) John Wordsworth Department of Computer Science The University.
Introduction to Core Database Concepts Getting started with Databases and Structure Query Language (SQL)
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
ITX2000 Remote hosts and web servers Prof. Xiaohong (Sharon) Gao Room: T125 Ext: Week 3 – MySQL – Statements.
3 A Guide to MySQL.
CS SQL.
MySQL: Part II.
Introduction to MySQL.
Introduction to MySQL.
IS444: Modern tools for applications development
IS444: Modern tools for applications development
MS Access Database Connection
Database.
PHP and MySQL.
Structured Types (9-12-2) Structured types allow composite attributes of E-R diagrams to be represented directly. Unnamed row types can also be used in.
Charles Severance Single Table SQL.
Presentation transcript:

CS252: Systems Programming Ninghui Li Based on Slides by Gustavo Rodriguez-Rivera Topic 18: SQL and Relational Databases

Relational Databases You have learned how to store data persistently into files. However, when using plane files, you have to write functions to parse the information, to search it etc. Relational databases (or just called Databases) store the information in tables. A table is made of many rows and columns, where one row stores a record and a column stores an attribute of the record. Databases provides functions to add, delete, and search records in a table. SQL (Structured Query Language) is the standard language used to manipulate databases.

Available SQL databases MySQL Very popular free database Oracle Very popular database for enterprise use Microsoft SQL Also very popular. © Gustavo Rodriguez-Rivera3

Structured Query Language (SQL) All major languages let you communicate with a database using SQL. Databases have a GUI program that lets you manipulate the database directly and can be used for database administration. You can think of a database as a group of named tables with rows and columns. Each column has a name and each row contains a set of related data.

Single Table TitleISBNFNameLNamePricePublisherURL A Guide to the SQL Standard AlexanderChristopher47.95Addison- Wesley bc.com A Pattern Language: Towns, Buildings, Construction Frederick P.Brooks65.00John Wiley & Sons m A Pattern Language: Towns, Buildings, Construction SmithPeter65.00John Wiley & Sons m

Structuring your information in Tables As part of the design of a project, you need to design the tables in a database. You may store your information in multiple tables to reduce the amount of repeated information. In the example before we could store, all the information in a single table but that would lead to many repeated entries.

SQL by Example (from textbook) Autor_IDNameFname ALEXAlexanderChristopher BROOBrooksFrederick P. SMITHSmithPeter Authors Table TitleISBNPublisher_IDPrice A Guide to the SQL Standard A Pattern Language: Towns, Buildings, Construction Books Table

SQL by Example (from textbook) ISBNAuthor_IDSeq_No ALEX BROO DAR1 BookAuthors Table Publisher_IDNameURL 0201Addison-Wesleywww.aw-bc.com 0407John Wiley & Sonswww.wiley.com Publishers Table

Primary Keys One or more of the columns of the table are defined as Primary Keys. The value in each column of a primary key is recommended to be unique. A separate data structure called B-tree is created for this Primary Key for quick access. Searches on this binary key will be at least O(log n), compared to searches in other columns that will be sequential.

SQL by Example By convention SQL keywords are written in uppercase. SELECT * FROM Books This query returns all rows in the Books table. SQL statements always require FROM SELECT ISBN, Price, Title FROM Books This query returns a table with only the ISBN, price and title columns from the Books table.

SQL by Example SELECT ISBN, Price, Title FROM Books WHERE Price <=29.95 This query returns a table with the ISBN, Price and Title from the Books table but only for the books where the price is less or equal to

SQL by Example SELECT ISBN, Price, Title FROM Books WHERE Title NOT LIKE %n_x% Returns a table with ISBN, Price and Title as columns excluding the books that contain Linux or UNIX in the title. The % character means any zero or more characters. _ means any single character.

SQL by Example SELECT Title, Name, URL FROM Books, Publishers WHERE Books.Publisher_ID=Publishers.Publisher_ID It returns a table with the Title, Name of publisher, and URL from Books and Publishers. TitleNameURL A Guide to the SQL Standard Addison-Wesleywww.aw-bc.com A Pattern Language: Towns, Buildings, Construction John Wiley & Sonswww.wiley.com

SQL by Example You can also use SQL to change data inside a database. UPDATE Books SET Price = Price – 5.00 WHERE Title Like %C++% This reduces the price by $5.00 for all books that have C++ in the title.

SQL by Example (from textbook) You can also delete rows with SQL DELETE FROM Books WHERE Title Like %C++% This deletes all books that have C++ in the title.

SQL by Example Use INSERT to insert a new row in the table. INSERT INTO Books VALUES (A Guide to the SQL Standard, , 0201, 47.95) This inserts a new book in the Books table.

SQL by Example You can also create a new table using SQL CREATE TABLE Books ( TITLE CHAR(60), ISBN CHAR(13), Publisher_ID CHAR(6), Price DECIMAL(10,2) )

SQL Tutorials For more information about SQL, see the SQL tutorial in You can also run some SQL examples there. © Gustavo Rodriguez-Rivera18

Running SQL in the SSLAB machines The explanation of how to run mysql inside your account in the sslab machines is in : HOWTO,_Linux The instructions allow you to run the database in the background but it will allow only to connect clients in the same machine. Here is the mysql tutorial. Follow the tutorial to get familiar with mysql.

Running mysql in the sslab machines To run mysql type: bash> mysql -u root mysql> CREATE DATABASE menagerie; mysql> USE menagerie mysql> SHOW TABLES; mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20), -> species VARCHAR(20), sex CHAR(1), birth DATE, death DATE); mysql> SHOW TABLES; mysql> DESCRIBE pet; mysql> INSERT INTO pet -> VALUES ('Puffball','Diane','hamster','f',' ',NULL); mysql> select * from pet;