SQL Rohit Khokher.

Slides:



Advertisements
Similar presentations
TURKISH STATISTICAL INSTITUTE 1 /34 SQL FUNDEMANTALS (Muscat, Oman)
Advertisements

Basic SQL Introduction Presented by: Madhuri Bhogadi.
Virtual training week 4 structured query language (SQL)
Database Systems: Design, Implementation, and Management Tenth Edition
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Structure Query Language (SQL) COMSATS INSTITUTE OF INFORMATION TECHNOLOGY, VEHARI.
Introduction to 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.
Structured Query Language Chapter Three (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Introduction to Structured Query Language (SQL)
Structured Query Language Chapter Three DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
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.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
Introduction to SQL J.-S. Chou Assistant Professor.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 4 th Edition.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Database A collection of related data. Database Applications Banking: all transactions Airlines: reservations, schedules Universities: registration, grades.
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
Introduction to SEQUEL. What is SEQUEL? Acronym for Structural English Query Language Acronym for Structural English Query Language Standard language.
SQL: Data Manipulation Presented by Mary Choi For CS157B Dr. Sin Min Lee.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
Using Special Operators (LIKE and IN)
SQL FUNDAMENTALS SQL ( Structured Query Language )
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.
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.
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 7 Introduction to Structured.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
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.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
IS 380 Introduction to SQL This lectures covers material from: database textbook chapter 3 Oracle chapter: 3,14,17.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
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.
1 CS 430 Database Theory Winter 2005 Lecture 10: Introduction to SQL.
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Oracle & SQL. Oracle Data Types Character Data Types: Char(2) Varchar (20) Clob: large character string as long as 4GB Bolb and bfile: large amount of.
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.
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.
 CONACT UC:  Magnific training   
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
SQL Query Getting to the data ……..
SQL 101.
DATABASE MANAGEMENT SYSTEM
STRUCTURED QUERY LANGUAGE
مقدمة في قواعد البيانات
Database systems Lecture 3 – SQL + CRUD
SQL Fundamentals in Three Hours
SQL .. An overview lecture3.
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Contents Preface I Introduction Lesson Objectives I-2
IST 318 Database Administration
SQL (Structured Query Language)
Presentation transcript:

SQL Rohit Khokher

INTRODUCTION Structured Query Language (SQL) is the standard command set that allows the users to interact with the relational database management systems. All task related to relational data management – creating tables, querying the database for information, modifying the data in database ,deleting them ,granting access to users and so on-can be easily performed using SQL.

ADVANTAGES SQL is coded with embedded data . Programmer needs to simply specify what data is required and not how to retrieve it unlike procedural language. Applications written in SQL can be easily ported across system. SQL as a language provides a greater degree of abstraction and is independent of the way it is implemented internally. A query return same result whether optimizing has been done with indexes or not.

Language is simple , easy to learn ,can also handle complex situations. Expected results are well defined and language has sound theoretical base and there is no ambiguity about the way a query will interrupt the data and produce the result. SQL can also be used to define data structures , control access to the data , delete , insert and modify occurence of the data.

CHARACTERISTICS SQL has rules for embedding SQL statements into a general purpose programming language such as java or COBOL. SQL is a non procedural language . SQL is not case sensitive. SQL has statements for data definition, query and update. Hence it is both a DDL and a DML. SQL usage by its very nature is extremely flexible. There is no need to start SQL statements in a particular column or be finished in a single line.

SQL COMMANDS SQL TCS DDL DML DAS DCL DQL

SQL COMMANDS SQL statements can broadly be classified into the following categories :- Data Definition Language (DDL):- The commands used are CREATE, ALTER and DROP. The data definition statements are CREATE TABLE, CREATE VIEW, CREATE INDEX, ALTER TABLE , DROP TABLE , DROP VIEW and DROP INDEX. Data Manipulation Language (DML):- SQL provides three data manipulation statements –INSERT, UPDATE , DELETE.

Data Query Language (DQL):- SQL has only one data query statement ,i.e. SELECT. It enables the users to query one or more tables to get the desired information. Data Control Language (DCL):- The DBA has the authority to give and take the privileges to a specific user. The DCL commands are GRANT and REVOKE.

Data Administration Statements (DAS):- Two data administration commands are START AUDIT and STOP AUDIT. Note that data administration is different from database administration .Database administration is the overall administration of the database and data administration is only a subset of that. Transaction Control Statements (TCS):- Some of the TCS are COMMIT , ROLLBACK , SAVEPOINT and SET TRANSACTION.

DATA TYPES Char (n):- A fixed character length string with user specified length. Varchar (n):- A variable character length string with user specified maximum length n. Int :- An integer. Small Integer :- A small integer. Numeric (p, d):- A fixed point number with user defined precision. Real , double precision:- Floating point and double precision floating point numbers with machine dependent precision.

Float (n) :- A floating point number, with precision of at least n digits. Date :- A calendar date containing a ( four digits) year , month and day of the month. Time:- The time of day , in hours, minutes and seconds e.g. Time ’09:30:00’. Number:-Number is used to store numbers (fixed or floating point).

Creation Of A Table Create table Client_master ( client_no varchar (06) , name varchar (20), city varchar (15), pincode number (06), bal_due number (10,2) );  desc client_master /*to show all the columns*/

Inserting Values Insert into client_master values (‘0001’,’Amit’,’Mumbai’,400054,1500); insert into client_master values (‘0002’,’Vandana’, ‘Chennai’,780001,0); RETRIEVING OF DATA FROM TABLE :-SELECT * from client_master; /* to show all the rows of a table*/

Client_master Bal_due Client_no Name City Pincode Amit Mumbai 400054 15000 0001 780001 Chennai Vandana 0002 5000 400057 Mumbai Pramada 0003 400056 Mumbai 0004 Basu 100001 2000 Delhi 0005 Ravi Mumbai 400050 0006 Rupa

QUERIES Find out the names of all the clients. SQL> SELECT name 2 from client_master; List all the clients who are located in ‘Mumbai’. SQL> SELECT * 2 from client_master where 3 city= ‘Mumbai’ ; OR 2 from client_master where 3 city in (‘Mumbai’) ; OR

SQL> SELECT * 2 from client_master where 3 city like ‘M%’ ; Display the information for client no 0001 and 0002. 3 client_no =0001 OR client_no=0002;

Delete the record with client 0001 from the client_master table. SQL> DELETE from client_master 2 where client_no=0001; Change the city of client_no 0005 to Mumbai. SQL> UPDATE client_master 2 SET city=‘Mumbai’ where 3 client_no=0005;

Sorting of data in table:- SQL> SELECT * 2 from client_master 3 ORDER BY name; Grouping while selecting :- 3 GROUP BY city;

AGGREGATE FUNCTIONS COUNT (*):- produces the number of rows on non NULL field values that the query selected. Ex:- SQL> SELECT COUNT (*) 2 from client_master; SUM():- produces the arithmetic sum of all selected values of a given field. Ex:- SQL> SELECT SUM (bal_due) AVG():- produces the average (mean) of all selected values of a given field. Ex:-

SQL> SELECT AVG (bal_due) 2 from client_master; MAX():- produces the largest of all selected values of a given field. MIN():- produces the smallest of all selected values of a given field. Ex:- SQL> SELECT MAX (bal_due), 2 MIN (bal_due) from 3 client_master;

STRUCTURE OF TABLE PRIMARY KEY:- SQL> ALTER TABLE client_master 2 ADD PRIMARY KEY (client_no); FOREIGN KEY:- SQL> ALTER TABLE department 2 FOREIGN KEY (dept_no) 3 references client_master; Adding new columns:- 2 ADD ( address varchar(20)); UNIQUE:- 2 MODIFY ( pincode varchar(06));

NOT NULL:- SQL> ALTER TABLE client_master 2 MODIFY ( client_no varchar(06)); DROP STATEMENT:- SQL> DROP TABLE client_master; Modifying existing table:- 2 MODIFY ( client_no varchar(10));  CHECK:- SQL> ALTER TABLE student 2 ADD CHECK (marks>50);

JOINS Self Join:- SQL> SELECT s.name ,t.name , 2 s.courseid from student a, 3 student b where 4 a.courseid= b.courseid; Left/Right outer join:- SQL> SELECT course.courseid, cname , 2 name from student LEFT/RIGHT 3 OUTER JOIN course on 4 student.courseid = course.courseid; Cartesian Product:- SQL> SELECT, student.*, course.* 2 from student , course;

SET OPERATIONS Union:- SQL> SELECT name, city from 2 student UNION SELECT sname, 3 city from head; Difference:- SQL> SELECT name from student 2 MINUS SELECT from head; Intersect:- SQL> SELECT name from 2 student INTERSECT SELECT sname from 3 head;

VIEW You can present logical subsets or combinations of data by creating views of tables . A view is a logical table based on a table or another view. A view contains no data of its own but is like a window through which data from tables can be viewed or changed. The view is stored as a SELECT statement in the data dictionary. Uses:- :- To restrict data access. :- To make complex queries easy. :- To provide data independence. :- To present different views of the same data.

SYNTAX:- CREATE VIEW viewname as SELECT columnname, columnname from tablename; Ex:- SQL> CREATE VIEW c_view 2 SELECT name, city 3 from client_master; Removing a View:- SQL> DROP VIEW c_view ;

INDEXES An index is an ordered list of a column or group of columns in a table. An index created on the single column of the table is called simple index. When multiple table columns are included in the index it is called composite index. SYNTAX(SIMPLE):- CREATE INDEX index_name ON table name (column name); Ex:- SQL> CREATE INDEX client_index 2 ON client_master ( pincode);

Composite Index:- CREATE INDEX index_name ON table name (column name, column name); Ex:- SQL> CREATE INDEX client_cindex 2 ON client_master (client_no, name); Unique Index:- Ex:- SQL> CREATE UNIQUESTION INDEX c_index 2 ON client_master (state);

Dropping Indexes:- An index can be dropped by using DROP INDEX. SYNTAX:- DROP INDEX indexname; Ex:- SQL> DROP INDEX client_index;