SQL.

Slides:



Advertisements
Similar presentations
Basic SQL Introduction Presented by: Madhuri Bhogadi.
Advertisements

Virtual training week 4 structured query language (SQL)
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Introduction to Structured Query Language (SQL)
MY SQL Eng: SAHAR. Introduction to SQL What is SQL? When a user wants to get some information from a database file, he can issue a query A query is a.
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.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
ASP.NET Programming with C# and SQL Server First Edition
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.
2440: 141 Web Site Administration Database Management Using SQL Professor: Enoch E. Damson.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Lecture6:Data Manipulation in SQL, Simple SQL queries Prepared by L. Nouf Almujally Ref. Chapter5 Lecture6 1.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Database: SQL and MySQL
CPS120: Introduction to Computer Science Lecture 19 Introduction to 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.
DATA MANIPULATION andCONTROL
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
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.
DAT602 Database Application Development Lecture 3 Review of SQL Language.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
LOGO 1 Lab_04: Basic SQL. 2 Outline  The ORDER BY Keyword  SQL ORDER BY Syntax  SQL NULL Values.
SQL. คำสั่ง SQL SQL stands for Structured Query Language is a standard language for accessing and manipulating databases.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
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.
Introduction to Database SEM I, AY Department of Information Technology Salalah College of Technology Chapter No.3 SQL.
به نام خدا SQL QUIZ جوانمرد Website: ejavanmard.blogfa.com.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
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.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
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.
Fundamentals of DBMS Notes-1.
Web Systems & Technologies
CHAPTER 7 DATABASE ACCESS THROUGH WEB
SQL Query Getting to the data ……..
Chapter 5 Introduction to SQL.
MySQL DML Commands By Prof. B.A.Khivsara
Insert, Update and the rest…
Introduction to Structured Query Language(SQL)
SQL Creating and Managing Tables
SQL Creating and Managing Tables
SQL Tutorial.
Chapter 7 Working with Databases and MySQL
Chapter 8 Working with Databases and MySQL
SQL Creating and Managing Tables
CIS16 Application Programming with Visual Basic
JOINS (Joinining multiple tables)
Unit-3 Interactive SQL.
Introduction To Structured Query Language (SQL)
Access: SQL Participation Project
SQL DATA CONSTRAINTS.
Introduction To Structured Query Language (SQL)
JOINS (Joinining multiple tables)
Concept of grouping SELECT statement have:
Presentation transcript:

SQL

Introduction to SQL What is SQL? When a user wants to get some information from a database file, he can issue a query. A query is a user–request to retrieve data or information with a certain condition. SQL is a query language that allows user to specify the conditions. (instead of algorithms)

Introduction to SQL Concept of SQL The user specifies a certain condition. The program will go through all the records in the database file and select those records that satisfy the condition.(searching). Statistical information of the data. The result of the query will then be stored in form of a table.

Create table command This command is use for creating a table. Rules for creating tables A name can have maximum upto 30 characters. A-Z , a-z , 0-9 allowed A name should be begin with an alphabet The use of special character like _ allowed and also recommaended SQL reversed words not allowed.(ex. create , select and so on.)

Create new table CREATE TABLE TABLENAME (<ATTRIBBUTES> <DATATYPE> <SIZE>); EX: create table persons(P_ID number(10),LASTNAME varchar2(20),FIRSTNAME varchar2(20),ADDRESS varchar2(20),CITY varchar2(15)); Table Created. Select * from persons; P_ID LASTNAME FIRSTNAME ADDRESS CITY

Now Display all the table Query : Select * from tab; Display list of tables. Displaying Table Structure Query : DESC PRSONS;

INSERT DATA INTO TABLE SYNTAX : INSERT INTO table_name VALUES (value1, value2, value3,...); Now we want to insert values in table persons QUERY INSERT INTO persons values(1,’SHAH’,’CHINTAN’,’SATELLITE’,’AHMEDABAD’); 1 row created

INSERT multiple rows in table QUERY INSERT INTO persons values(&ID,’&LASTNAME,’&FIRSTNAME’,’&ADDRESS’,’&CITY’); Enter value for ID : 1 . 1 row created Press / and enter

VIEWING DATA IN THE TABLES SELECT * FROM PERSONS;

Filtering Table Data Selected Columns And All Rows Syntax : SELECT <columnname1>,<columnname2> FROM Table Name ; Example : SELECT P_ID , LASTNAME FROM PERSONS; P_ID LASTNAME 1 SHAH 2 PATEL 3 PANDYA 4

Filtering Table Data Selected Rows and All Columns Syntax : SELECT * FROM <Table Name> WHERE <Condition> ; Example : SELECT * FROM PERSONS WHERE NAME=‘NITIN’; P_ID LASTNAME FIRSTNAME ADDRESS CITY 3 Nitin Pandya Gandhinagar

Distinct Eliminating duplicate rows -The DISTINCT clause removing duplicates from the result set. -The DISTINCT clause can only used with select statements. -SELECT DISTINCT Syntax SELECT DISTINCT <COLUMNNAME1> FROM <TABLENAME>;

We use the following SELECT Statement We use the following SELECT Statement. SELECT DISTINCT city FROM persons; P_ID LASTNAME FIRSTNAME ADDRESS CITY 1 Chintan Shah Satellite Ahmedabad 2 Sanjay Patel Gandhinagar 3 Nitin Pandya CITY Ahmedabad Gandhinagar

SORTING DATA IN A TABLE Orcle allows data from a table to be viewed in a sorted orders. The rows retrieved from the table will be sorted in either ascending or descending order. The ORDER BY keyword is used to sort the result-set by specified column. The ORDER BY keyword sort the records in ascending order by default. If you want to sort the records in a descending order, you can use the DESC keyword.

SQL ORDER BY Syntax SELECT column_name(s) FROM table_name ORDER BY column_name(s) ASC|DESC P_ID LASTNAME FIRSTNAME ADDRESS CITY 1 SHAH CHINTAN SATELLITE AHMEDABAD 2 PATEL SANJAY GANDHINAGAR 3 PANDYA NITIN TALOD 4 VISHAL GHATLODIA

We use the following SELECT statement: SELECT We use the following SELECT statement: SELECT * FROM persons ORDER BY LASTNAME; P_ID LASTNAME FIRSTNAME ADDRESS CITY 3 PANDYA NITIN TALOD GANDHINAGAR 2 PATEL SANJAY 4 VISHAL GHATLODIA AHMEDABAD 1 SHAH CHINTAN SATELLITE

ORDER BY DESC example SELECT * FROM persons ORDER BY LASTNAME DESC; P-ID LASTNAME FIRSTNAME ADDRESS CITY 1 SHAH CHINTAN SATELLITE AHMEDABAD 4 PATEL VISHAL GHATLODIA 2 SANJAY GANDHINAGAR 3 PANDYA NITIN TALOD

DELETE Statement Removal of all ROWS -Syntax DELETE FROM PERSONS; -All rows deleted

Question: - If I want to retrieve data of persons table. What will happen? What will be an answer?

UPDATING CONTENS OF A TABLE The UPDATE command is used to change or modify data values in a table. SQL UPDATE Syntax UPDATING ALL ROWS UPDATE <TABLENAME> SET <COLUMNNAME1>=<NEW VALUE> , <COLUMNNAME2>=<NEW VALUE>;

Example Now we want to UPDATE LASTNAME in persons table UPDATE persons SET LASTNAME=‘ABC’;

-Now, what will be effect? -How looks table(persons) P_ID LASTNAME FIRSTNAME ADDRESS CITY 1 ABC CHINTAN SATELLITE AHMEDABAD 2 SANJAY GANDHINAGAR 3 NITIN TALOD 4 VISHAL GHATLODIA UPDATE records Conditionally UPDATE table_name SET columnname=value, columnname=value2 WHERE columnname=value;

Now we want to UPDATE CITY from Ahmedabd to Bombay, whose FIRSTNAME IS CHINTAN UPDATE Persons SET CITY=‘BOMBAY’ WHERE FIRSTNAME=‘CHINTAN’; What will be result and how looks table?

-What will be result and how looks table? P_ID LASTNAME FIRSTNAME ADDRESS CITY 1 SHAH CHINTAN SATELLITE BOMBAY 2 PATEL SANJAY GANDHINAGAR 3 PANDYA NITIN TALOD 4 VISHAL GHATLODIA AHMEDABAD

MODIFY STRUCTURE OF TABLE ADDING new columns in existing table. Syntax ALTER TABLE <TABLENAME> ADD(<NEW COLUMNNAME><DATATYPE>(<SIZE>));

Now we want to ADD PINCODE fields in PERSONS table Query ALTER TABLE persons ADD(PINCODE NUMBER(6)); OUTPUT: - P_ID LASTNAME FIRSTNAME ADDRESS CITY PINCODE 1 SHAH CHINTAN SATELLITE AHMEDABAD 2 PATEL SANJAY GANDHINAGAR 3 PANDYA NITIN TALOD 4 VISHAL GHATLODIA

EXERCISE TIME NOW INSERT/UPDATE PINCODE IN PERSONS TABLE. Your table looks like this. P_ID LASTNAME FIRSTNAME ADDRESS CITY PINCODE 1 SHAH CHINTAN SATELLITE AHMEDABAD 380015 2 PATEL SANJAY GANDHINAGAR 382051 3 PANDYA NITIN TALOD 382055 4 VISHAL GHATLODIA 380009

MODIFY STRUCTURE OF TABLE MODIFY columns in existing table. Syntax ALTER TABLE <TABLENAME> MODIFY(<COLUMNNAME><NEWDATATYPE> (<NEWSIZE>));

MODIFY(PINCODE VARCHAR2(10)); Now we want to MODIFY PINCODE data type from NUMBER TO VARCHAR2 in PERSONS table. Query ALTER TABLE persons MODIFY(PINCODE VARCHAR2(10)); OUTPUT: - TABLE ALTERED.

RENAMING TABLES SYNTAX : RENAME <TableName> TO <NewTableName> EXAMPLE : RENAME PERSONS TO CLIENTS; TABLE RENAMED

TRUNCATING TABLES DESTROYING TABLES EXAMPLE : TRUNCATE TABLE PERSONS; Table Truncatd. DESTROYING TABLES EXAMPLE: DROP TABLE PERSONS; Table Dropped.