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”

Slides:



Advertisements
Similar presentations
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Advertisements

Database Basics I101 Summer 2006 Copyright 2004, Matt Hottell.
Beginning SQL Tutorial Author Jay Mussan-Levy. What is SQL?  Structured Query Language  Communicate with databases  Used to created and edit databases.
Introduction to Structured Query Language (SQL)
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
This course has taken from This unique introductory SQL tutorial not only provides easy-to-understand SQL instructions, but it allows.
CSE 190: Internet E-Commerce Lecture 10: Data Tier.
19-Jun-15 SQL. SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell” is the only correct.
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.
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.
Introduction to Structured Query Language (SQL)
Structured Query Language Chapter Three DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
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,
Oracle Data Definition Language (DDL)
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Database Lecture # 1 By Ubaid Ullah.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Structured Query Language. SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database systems.
Database A collection of related data. Database Applications Banking: all transactions Airlines: reservations, schedules Universities: registration, grades.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
Introduction to SQL Steve Perry
2440: 141 Web Site Administration Database Management Using SQL Professor: Enoch E. Damson.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
Database: SQL and MySQL
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
1 What is database 2? What is normalization? What is SQL? What is transaction?
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.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
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 Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
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,
SQL CREATING AND MANAGING TABLES lecture4 1. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
Chapter 11 Database and SQL. Flat Files and Databases Flat files Databases Advantages Efficient use of resources Access control Disadvantages Security.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
Introduction to Database SEM I, AY Department of Information Technology Salalah College of Technology Chapter No.3 SQL.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
Creating and Managing Tables. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically represents subsets.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Quiz Questions Q.1 An entity set that does not have sufficient attributes to form a primary key is a (A) strong entity set. (B) weak entity set. (C) simple.
JDBC.
SQL data definition using Oracle
Oracle Data Definition Language (DDL)
Structured Query Language
MIS2502: Data Analytics SQL 4– Putting Information Into a Database
SQL (Structured Query Language)
Presentation transcript:

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” is the only correct pronunciation SQL is a language for accessing and updating databases SQL is an ANSI (American National Standards Institute) standard Just about every relational database supports SQL Most also extend it in various incompatible ways

Databases A database contains one or more tables Each table has a name A table consists of rows and columns A row is a record: it contains information about a single entity (such as a person) Columns have names that tell what kind of information is stored in that column (for example, “Address”) The information in a cell may be of various types: string, integer, floating point number, date, blank, etc. A value of null means the data for that cell is missing Two null values are not considered to be equal

People First_NameLast_NameGenderAgePhone JohnSmithM SallyJonesF JohnWhiteM MarySmithF Example table People is the name of the table Each row is a record Each cell in a column contains the same kind of information In this example, no single column contains unique information (there are two “John”s, etc.)

Primary Keys We will want to look things up in a table To do that, we need a way of choosing a particular row A primary key is a column, or group of columns, whose values uniquely identify each row Example: In the previous table, no single column could be used as a primary key Multiple people had the same first name, same last name, same gender, same age, and same telephone number No two people had the same first name and last name First_name and Last_name could be used as a primary key It’s a lot more convenient to have a single column as a primary key

Integrity Tables must follow certain integrity rules: No two rows may be completely identical Any column that is a primary key, or part of a primary key, cannot contain null values There are some other rules about arrays and repeating groups that need not concern us here

DDL and DML SQL contains two kinds of “languages” (statement types) DDL is the Data Definition Language; it defines the structure of tables CREATE TABLE -- creates a new database table ALTER TABLE -- alters (changes) a database table DROP TABLE -- deletes a database table DML is the Data Manipulation Language; it defines and manipulates the content of tables INSERT -- puts new data into the database SELECT -- gets data from the database UPDATE -- updates (changes) data in the database DELETE -- removes data from the database

CREATE TABLE Syntax: CREATE TABLE table_name ( column_name data_type constraint, …, column_name data_type constraint ); Names, such as the table_name and the column_names, are not quoted The data_types will be described shortly The constraints are optional Notice where there are commas (and where there aren’t)

Common data types char( size ) Fixed-length character string (maximum of 255 characters) varchar( size ) Variable-length character string (maximum of size characters) number( size ) Integer value (max size digits) number( size, d ) Decimal number value; maximum of size digits total, with not more than d digits to the right of the decimal date A calendar date

Example table creation CREATE TABLE People ( First_Name VARCHAR(12), Last_Name VARCHAR(25), Gender CHAR(1), Age NUMBER(3), Phone CHAR(6) ); People First_NameLast_NameGenderAgePhone JohnSmithM SallyJonesF JohnWhiteM MarySmithF

Constraints When a table is created, constraints can be put on the columns unique -- no repeated values in this column primary key -- unique and used to choose rows not null -- must have a value

ALTER TABLE ALTER TABLE table_name ADD column_name datatype Adds a column to the table ALTER TABLE table_name DROP COLUMN column_name Removes a column (and all its data) from the table DROP COLUMN is not available on all SQL platforms

DROP TABLE Syntax: DROP TABLE table_name ; Just deleting all the rows from a table leaves a “blank” table with column names and types The DROP TABLE command removes the table from the database completely

SELECT Syntax: SELECT columns FROM table WHERE condition ; columns is: a comma-separated list of column names, or * to indicate “all columns” table is the name of the table condition is an optional condition to be satisfied Examples: SELECT First_Name, Last_Name FROM People; SELECT * FROM People WHERE age < 40;

How SELECT works SELECT First_Name, Last_Name FROM People WHERE Age > 30; People First_NameLast_NameGenderAgePhone JohnSmithM SallyJonesF JohnWhiteM MarySmithF JohnWhite MarySmith Result:

Names and strings SQL keywords (such as SELECT ) are case insensitive, but are traditionally written in all uppercase letters Table names and column names may or may not be case sensitive Data values presumably are case sensitive String data must be enclosed in single quotes

Conditions < Less than <= Less than or equal = Equal <> Not equal to ( != works on some databases) >= Greater than or equal > Greater than LIKE String equality; % may be used as a wildcard … WHERE First_Name LIKE 'Jo%'; matches Joe, John, Joanna, etc. AND, OR and NOT can be used with conditions

Operators Basic arithmetic operators are defined in SQL: + add - subtract * multiply / divide % modulus (remainder)

INSERT INTO Syntax: INSERT INTO table_name ( column, …, column ) VALUES ( value, …, value ); The columns are the names of columns you are putting data into, and the values are that data String data must be enclosed in single quotes Numbers are not quoted You can omit the column names if you supply a value for every column

UPDATE Syntax: UPDATE table_name SET column_name = new_value WHERE column_name = value ; Example: UPDATE Person SET age = age + 1 WHERE First_Name = 'John' AND Last_Name = 'Smith';

DELETE DELETE FROM table_name WHERE column_name = some_value ; Examples: DELETE FROM Person WHERE Last_Name = 'Smith'; DELETE FROM Person; Deletes all records from the table!

Joins I: INNER JOIN A join lets you collect information from two or more tables and present it as a single table Joins require the use of primary keys An INNER JOIN returns all rows from both tables where there is a match Example: SELECT Employees.Name, Orders.Product FROM Employees INNER JOIN Orders ON Employees.Employee_ID=Orders.Employee_ID The result is a table of employee names and the products they ordered Only employees that have ordered products are listed

Joins II: LEFT JOIN A LEFT JOIN returns all matching rows from the first table, even if there are no matching rows in the second table Example: SELECT Employees.Name, Orders.Product FROM Employees LEFT JOIN Orders ON Employees.Employee_ID=Orders.Employee_ID The result is, again, a table of employee names and the products they ordered All employees are listed If an employee has not ordered a product, that cell is blank

Joins III: RIGHT JOIN A RIGHT JOIN returns all matching rows from the second table, even if there are no matching rows in the first table Example: SELECT Employees.Name, Orders.Product FROM Employees RIGHT JOIN Orders ON Employees.Employee_ID=Orders.Employee_ID The result is, once again, a table of employee names and the products they ordered All employees who ordered a product are listed All products are listed If a product was ordered, but not by an employee, that employee cell is left blank

MySQL MySQL is an open source database server Like much open source software, MySQL is a very solid, stable product Also like much open source software, MySQL hasn’t been well productized (made easy for end user to install and configure) Oracle is the most widely used commercial database server MySQL doesn’t give you all the features of Oracle For most jobs you don’t need these features anyway If you don’t use implementation-specific features, it’s easy to move from one SQL database to another InstantRails comes with MySQL InstantRails can be used with any SQL server One known exception: Microsoft Access

The End