SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.

Slides:



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

Basic SQL Introduction Presented by: Madhuri Bhogadi.
Manipulating Data Schedule: Timing Topic 60 minutes Lecture
Virtual training week 4 structured query language (SQL)
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.
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
CS 104 Introduction to Computer Science and Graphics Problems Introduction to Database (2) Basic SQL 12/05/2008 Yang Song.
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.
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.
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
SQL (DDL & DML Commands)
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.
ACTION QUERIES (SQL COMMANDS ) STRUCTURED QUERY LANGUAGE.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
Nitin Singh/AAO RTI ALLAHABAD 1 SQL Nitin Singh/AAO RTI ALLAHABAD 2 OBJECTIVES §What is SQL? §Types of SQL commands and their function §Query §Index.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
SQL Unit – 2 Base Knowledge Presented By Mr. R.Aravindhan.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL Structured Query Language 1. Data Definition Language (DDL) is used to manage table and define data structure i.e. CREATE, ALTER, DROP Data Control.
SQL. คำสั่ง SQL SQL stands for Structured Query Language is a standard language for accessing and manipulating databases.
DatabaseDatabase cs453 Lab5 1 Ins.Ebtesam AL-Etowi.
Chapter 8 Part 2 SQL-99 Schema Definition, Constraints, Queries, and Views.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
DBSQL 5-1 Copyright © Genetic Computer School 2009 Chapter 5 Structured Query Language.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
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.
SQL.. AN OVERVIEW lecture3 1. Overview of SQL 2  Query: allow questions to be asked of the data and display only the information required. It can include.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
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.
Introduction to Database SEM I, AY Department of Information Technology Salalah College of Technology Chapter No.3 SQL.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
1 Designing Tables for a Database System. 2 Where we were, and where we’re going The Entity-Relationship model: Used to model the world The Relational.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
Fundamentals of DBMS Notes-1.
CHAPTER 7 DATABASE ACCESS THROUGH WEB
SQL Query Getting to the data ……..
The Basics of Data Manipulation
Introduction to Structured Query Language(SQL)
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
The Basics of Data Manipulation
“Manipulating Data” Lecture 6.
مقدمة في قواعد البيانات
SQL Queries Chapter No 3.
CMPT 354: Database System I
“Manipulating Data” Lecture 6.
SQL .. An overview lecture3.
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
ISC321 Database Systems I Chapter 4: SQL: Data definition, Constraints, and Basic Queries and Updates Fall 2015 Dr. Abdullah Almutairi.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Instructor: SAMIA ARSHAD
Structured Query Language Path from Unorganized to Organized….
DATABASE Purpose of database
SQL (Structured Query Language)
Presentation transcript:

SQL Basics

What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.

What Can SQL do? Can execute queries against a database. Can retrieve data from a database. Can insert records in a database. Can update records in a database.

What Can SQL do? Can delete records from a database. Can create new databases. Can create new tables in a database.

SQL Statements Most of the actions you need to perform on a database are done with SQL statements. Ex: select all the records in the "Person" table.  SELECT * FROM Person

Keep in Mind That... SQL is not case sensitive

7 SQL Transaction control Commit Rollback DML Select Insert Update Delete DDL Create Alter Drop DCL Grant Revoke

 Is used to change structure of database  Create Table  Drop Table  Alter Table 8 Data Definition Language (DDL)

Create Table The Create table statement is used to create a table in a database and to add constraints. –Constraints: NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY CHECK DEFAULT

The data types Ex: some popular data types used in creating fields. Data Type Name INT DOUBLE CHAR(n) VARCHAR(n) DATE TIME

CREATE TABLE person( id int, name varchar(50) not null, varchar(50), age int default 18, Dept_ID int, primary key(id), check(age>17), unique( ), foreign key (Dept_ID) REFERENCES Department(Dept_ID)) Create Table Example

Drop Table Used to remove a relation (base table) and its definition The relation can no longer be used in queries, updates, or any other commands since its description no longer exists Example: DROP TABLE DEPENDENT;

Alter Table Used to modify the table design like add a column, modify a column or delete a column. Examples: ALTER TABLE EMPLOYEE ADD JOB VARCHAR(12) ALTER TABLE EMPLOYEE MODIFY COLUMN JOB VARCHAR(50) ALTER TABLE EMPLOYEE DROP COLUMN JOB

 Used to manipulate database data 14 Data Manipulation Language (DML)

 SELECT o Extracts data from a database  INSERT INTO o Inserts new data into a database  UPDATE o Updates data in a database  DELETE o Deletes data from a database 15 Data Manipulation Language (DML)

INSERT INTO Statement First form: It doesn't specify the column names where the data will be inserted, only their values. –The previous form the attribute values should be listed in the same order as the attributes were specified in table. 16 INSERT INTO Employee VALUES ( 4,'Ahmed', ‘Ali', , ' ', '15 Ali fahmy St.Giza‘, ‘M’,1300,223344,10 )

INSERT INTO Statement, (cont.) Second form: It specifies both the column names and the values to be inserted 17 INSERT INTO Employee ( SSN, Lname, fname ) VALUES ( 5, ‘Ahmed', ‘Ali')

To insert a new row into table with identity value, we will not have to specify a value for the identity column (a unique value will be added automatically): insert into Department values('DP2','56733') insert into Department(Dname,MGRSSN) values('DP2','56733') INSERT INTO Statement, (cont.)

UPDATE Statement The UPDATE statement is used to update existing records in a table. SQL Syntax –UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value Note: The WHERE clause specifies which record or records that should be updated. If you omit the WHERE clause, all records will be updated! UPDATE Person SET Address='18 Abaas El 3akaad St. Nasr City.Cairo', City='Cairo' WHERE Lname=‘Amr' AND Fname='Ali'

DELETE Statement The DELETE statement is used to delete rows in a table. 20 delete from Employee where Lname='Brown’

SELECT Statement Basic form of the SQL SELECT statement is called a mapping or a 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

Or: SELECT Statement Examples SELECT Lname,Fname FROM Person SELECT Person.Lname, Person.Fname FROM Person SELECT * FROM Person WHERE City='Sandnes'

LIKE Operator Example SELECT * FROM Person WHERE City LIKE 's%' SELECT * FROM Person WHERE City LIKE '%s' SELECT * FROM Person WHERE City LIKE '_andnes' Used to represent one character

SQL AND & OR Operators AND operator displays records when all conditions are true. OR operator displays records when any condition is true.

SQL AND & OR Operators Example

IN Operator Example Retrieve data of all employees whose social security numbers number is , or –Query : SELECT * FROM Employee WHERE SSN IN (112233,512463)

IN Operator Example Retrieve data of all employees whose social security numbers number is not , or –Query : SELECT * FROM Employee WHERE SSN not IN (112233,512463)

The BETWEEN Operator The BETWEEN operator is used in a WHERE clause to select a range of data between two values. Retrieve the employees with salary between 1000 and 2000 –Query : SELECT * FROM EMPLOYEE WHERE SALARY BETWEEN 1000 AND 2000

NULLS IN SQL QUERIES SQL allows queries that check if a value is NULL. SQL uses IS or IS NOT to compare Nulls. Retrieve the names of all employees who do not have supervisors. –Query : SELECT FNAME, LNAME FROM EMPLOYEE WHERESUPERSSN IS NULL

DISTINCT Keyword The keyword DISTINCT is used to eliminate duplicate tuples in a query result.

Thank You