SQL has several parts: Major ones: DDL – Data Definition Language {Defining, Deleting, Modifying relation schemas} DML – Data Manipulation Language {Inserting,

Slides:



Advertisements
Similar presentations
介紹 元智大學電機工程所 碩士班一年級 蕭觀華 學號 : MySQL 介紹大綱 What is MySQL ? How to install on Linux Tutorial Introduction Database Administration MySQL Perl API Q&A.
Advertisements

Introduction to MySQL. 2 Road Map  Introduction to MySQL  Connecting and Disconnecting  Entering Basic Queries  Creating and Using a Database.
Action Queries CS 320. Review: SQL Command Types  Data Definition Language (DDL)  Used to create and modify database objects  Data Manipulation Language.
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.
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
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.
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”
Creating Database Tables CS 320. Review: Levels of data models 1. Conceptual: describes WHAT data the system contains 2. Logical: describes HOW the database.
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.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
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.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch Via Yoonsuck Choe.
Copyright © Curt Hill SQL The Data Definition Language.
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
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.
SQL Training SQL Statements – Part 1. Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. Lesson Objectives Explain the role of SQL.
Dbwebsites 2.1 Making Database backed Websites Session 2 The SQL… Where do we put the data?
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
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.
MySQL Databases & PHP Integration Using PHP to write data to, and retrieve data from, a MySQL database.
CSC 2720 Building Web Applications Database and SQL.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
Most information comes from Chapter 3, MySQL Tutorial: 1 MySQL: Part.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
© 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.
What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Visual Programing SQL Overview Section 1.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
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)
Chungbuk HRDI of KCCI PhD Kang,Won-Chan PHP Programming (MySQL)
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)
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.
Chapter 3: Relational Databases
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
Understand Data Definition Language (DDL) Database Administration Fundamentals LESSON 1.4.
ITX2000 Remote hosts and web servers Prof. Xiaohong (Sharon) Gao Room: T125 Ext: Week 3 – MySQL – Statements.
Introduction to Database Programming with Python Gary Stewart
3 A Guide to MySQL.
Fundamentals of DBMS Notes-1.
CS 3630 Database Design and Implementation
Chapter 5 Introduction to SQL.
Introduction to MySQL.
Introduction to MySQL.
Introduction to Oracle9i: SQL
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
CS3220 Web and Internet Programming SQL and MySQL
MySQL Database System Installation Overview SQL summary
CS3220 Web and Internet Programming SQL and MySQL
Database Instructor: Bei Kang.
SQL (Structured Query Language)
Presentation transcript:

SQL has several parts: Major ones: DDL – Data Definition Language {Defining, Deleting, Modifying relation schemas} DML – Data Manipulation Language {Inserting, Deleting, Modifying tuples in database} Embedded SQL – defines how SQL statements can be used with general-purposed programming

SQL For help: shell> mysql --help Using SQL: On any solaris/linux you have to use this to log on to MySQL: shell> /usr/local/mysql/bin/mysql -h faure -D loginname -p Basic Query: select A 1, A 2,…,A n from r 1, r 2, …,r m where P A 1, A 2,…,A n represent attributes r 1, r 2, …r m represent relations P represents predicate (guard condition)

Representations: Prompt Meaning mysql> Ready for new command. -> Waiting for next line of multiple-line command. ‘> Waiting for next line, collecting a string that begins with a single quote (` ’ ’). “> Waiting for next line, collecting a string that begins with a double quote (` ” ’). mysql> SELECT * -> FROM my_table -> WHERE name = “Smith” AND age < 30; mysql> SELECT * FROM my_table WHERE name = “Smith” AND age < 30; \c to cancel the execution of a command Keywords may be entered in any letter case: mysql> SELECT VERSION(), CURRENT_DATE; mysql> select version(), current_date; mysql> SeLeCt vErSiOn(), current_DATE; mysql> SELECT SIN(PI()/4), (4+1)*5;

Creating and Using a Database mysql> SHOW DATABASES; SHOW statement can be used to find out the databases currently existing on the server mysql> USE testdb testdb is a database name. USE command does not need a semi colon and must be given in a single line. Database needs to be invoked in order to use it. mysql> CREATE DATABASE example; Database names are case-sensitive unlike keywords; Same applies for table names So example != Example != EXAMPLE or some other variant

Creating a Table mysql> SHOW TABLES; Displays the current list of tables mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20), -> species VARCHAR(20), sex CHAR(1), birth DATE, death DATE); mysql> SHOW TABLES; Will display the table with the table name pet Verification of the table can be done with DESCRIBE command mysql> DESCRIBE pet; | Field | Type | Null | Key | Default | Extra | | name | varchar(20) | YES | | NULL | | | owner | varchar(20) | YES | | NULL | | | species| varchar(20) | YES || NULL | | | sex | char(1) | YES | | NULL | | | birth | date | YES| | NULL | | | death | date | YES || NULL | |

Loading Data into a Table LOAD DATA uses a text file with single record in a line that match the attributes in the table. Useful for inserting when multiple records are involved. Example: pet.txt is a text file with a single record Nameowner species sex birth death WhistlerGwen bird \N \N mysql> LOAD DATA LOCAL INFILE "pet.txt" INTO TABLE pet; INSERT command can be used when records needs to be inserted one at a time. NULL can be directly inserted in the field column Example: mysql> INSERT INTO pet -> VALUES ('Puffball','Diane','hamster','f',' ',NULL); Using User Variables select from shop; select * from shop where or

Examples of some common queries CREATE TABLE shop ( article INT(4) UNSIGNED ZEROFILL DEFAULT ‘0000' NOT NULL, dealerCHAR(20) DEFAULT ‘’NOT NULL, price DOUBLE(16,2) DEFAULT '0.00’ NOT NULL, PRIMARY KEY(article, dealer)); INSERT INTO shop VALUES (1,'A',3.45),(1,'B',3.99),(2,'A',10.99),(3,'B',1.45),(3,'C',1.69), (3,'D',1.25),(4,'D',19.95); mysql> SELECT * FROM shop; | article | dealer | price | | 0001 | A | 3.45 | | 0001 | B | 3.99 | | 0002 | A | | | 0003 | B | 1.45 | | 0003 | C | 1.69 | | 0003 | D | 1.25 | | 0004 | D | | The maximum value for a column The row holding the maximum of a certain column Maximum of column per group The rows holding the group-wise maximum of a certain field

SELECT MAX(article) AS article FROM shop SELECT article, dealer, price FROM shop WHERE price=(SELECT MAX(price) FROM shop) (or) 1.Get the maximum price value from the table with a SELECT statement. 2.Using this value compile the actual query: SELECT article, dealer, price FROM shop WHERE price=19.95 SELECT article, MAX(price) AS price FROM shop GROUP BY article SELECT article, dealer, price FROM shop s1 WHERE price=(SELECT MAX(s2.price) FROM shop s2 WHERE s1.article = s2.article);