0
Introduction to Database         Presented By :- Avinash Agrawal
How to retrieve data from a database?             SQL QUERIES
Introduction to SQL.• SQL stands for Structured Query Language• SQL is a special-purpose programming  language designed fo...
What Can SQL do?•   SQL can execute queries against a database•   SQL can retrieve data from a database•   SQL can insert ...
SQL DML and DDL• SQL can be divided into two parts: The Data  Manipulation Language (DML) and the Data  Definition Languag...
HOW TO CREATE A DATABASE AND A TABLE ?• The CREATE DATABASE statement is used to create a database.  Syntax:-• CREATE DATA...
Start with the table “persons”.
The SQL SELECT StatementSQL SELECT Syntax:SELECTcolumn_name(s)FROM table_name andSELECT * FROMtable_name
The SQL SELECT DISTINCT StatementIn a table, some of the columns may contain duplicate values.This is not a problem, howev...
SQL WHERE Clause:The WHERE clause is used to extract only those records that fulfilla specified criterion.Syntax:SELECT co...
Operators Allowed in the WHERE Clause
SQL AND & OR Operators
The ORDER BY Keyword:-The ORDER BY keyword is used to sort the result-set by a specifiedcolumn.The ORDER BY keyword sorts ...
SQL INSERT INTO Statement The INSERT INTO statement is used to insert a new row in atable. SYNTAX:- INSERT INTO table_name...
SQL UPDATE StatementThe UPDATE statement is used to update existing records ina table.SQL UPDATE Syntax:-UPDATE table_name...
SQL DELETE StatementThe DELETE statement is used to delete rows in a table.SQL DELETE Syntax:-DELETE FROM table_nameWHERE ...
LIKE OPERATORThe LIKE operator is used to search for a specified pattern in a column.SQL LIKE SyntaxSELECT column_name(s)F...
SQL JoinsThe JOIN keyword is used in an SQL statement to query datafrom two or more tables, based on a relationship betwee...
SQL INNER JOIN Keyword:-The INNER JOIN keywordreturn rows when there is atleast one match in bothtables.SQL INNER JOIN Syn...
SQL LEFT JOIN Keyword:-returns all rows from the lefttable (table_name1), even ifthere are no matches in theright table (t...
SQL RIGHT JOIN :-The RIGHT JOIN keywordreturns all the rows from theright table (table_name2),even if there are no matches...
SQL FULL JOIN :-The FULL JOIN keywordreturn rows when there is amatch in one of the tables.SQL FULL JOIN SyntaxSELECT colu...
VIEW:-A view is a virtual table based on the result-set of an SQLstatement.A view contains rows and columns, just like a r...
SQL Creating a View                SQL Updating a View           SQL Dropping a ViewIn SQL, a view is a virtual table   Yo...
Avinash database
Upcoming SlideShare
Loading in...5
×

Avinash database

84

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
84
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Avinash database"

  1. 1. Introduction to Database Presented By :- Avinash Agrawal
  2. 2. How to retrieve data from a database? SQL QUERIES
  3. 3. Introduction to SQL.• SQL stands for Structured Query Language• SQL is a special-purpose programming language designed for managing data in database management systems (DBMS).• SQL lets you access and manipulate databases• SQL is an ANSI (American National Standards Institute) standard.
  4. 4. What Can SQL do?• SQL can execute queries against a database• SQL can retrieve data from a database• SQL can insert records in a database• SQL can update records in a database• SQL can delete records from a database• SQL can create new databases• SQL can create new tables in a database• SQL can create stored procedures in a database• SQL can create views in a database
  5. 5. SQL DML and DDL• SQL can be divided into two parts: The Data Manipulation Language (DML) and the Data Definition Language (DDL).DDL:- DML:-CREATE DATABASE - creates a new SELECT - extracts data from adatabase databaseALTER DATABASE - modifies a UPDATE - updates data in adatabase databaseCREATE TABLE - creates a new table DELETE - deletes data from aALTER TABLE - modifies a table databaseDROP TABLE - deletes a table INSERT INTO - inserts newCREATE INDEX - creates an index data into a database(search key)DROP INDEX - deletes an index
  6. 6. HOW TO CREATE A DATABASE AND A TABLE ?• The CREATE DATABASE statement is used to create a database. Syntax:-• CREATE DATABASE database_name CREATE DATABASE Example We use the following CREATE DATABASE statement:• CREATE DATABASE my_db• The CREATE TABLE statement is used to create a table in a database. Syntax:-• CREATE TABLE table_name ( column_name1 data_type, column_name2 data_type, column_name3 data_type, .... )
  7. 7. Start with the table “persons”.
  8. 8. The SQL SELECT StatementSQL SELECT Syntax:SELECTcolumn_name(s)FROM table_name andSELECT * FROMtable_name
  9. 9. The SQL SELECT DISTINCT StatementIn a table, some of the columns may contain duplicate values.This is not a problem, however, sometimes you will want to listonly the different (distinct) values in a table.The DISTINCT keyword can be used to return only distinct(different) values.SELECT DISTINCT SYNTAX:-SELECT DISTINCTcolumn_name(s)FROM table_name
  10. 10. SQL WHERE Clause:The WHERE clause is used to extract only those records that fulfilla specified criterion.Syntax:SELECT column_name(s)FROM table_nameWHERE column_name operator value
  11. 11. Operators Allowed in the WHERE Clause
  12. 12. SQL AND & OR Operators
  13. 13. The ORDER BY Keyword:-The ORDER BY keyword is used to sort the result-set by a specifiedcolumn.The ORDER BY keyword sorts the records in ascending order by default.If you want to sort the records in a descending order, you can use theDESC keyword. Syntax:- SELECT column_name(s) FROM table_name ORDER BY column_name(s) ASC|DESC
  14. 14. SQL INSERT INTO Statement The INSERT INTO statement is used to insert a new row in atable. SYNTAX:- INSERT INTO table_name VALUES (value1, value2, value3,...)
  15. 15. SQL UPDATE StatementThe UPDATE statement is used to update existing records ina table.SQL UPDATE Syntax:-UPDATE table_nameSET column1=value, column2=value2,...WHERE some_column=some_value
  16. 16. SQL DELETE StatementThe DELETE statement is used to delete rows in a table.SQL DELETE Syntax:-DELETE FROM table_nameWHERE some_column=some_value
  17. 17. LIKE OPERATORThe LIKE operator is used to search for a specified pattern in a column.SQL LIKE SyntaxSELECT column_name(s)FROM table_nameWHERE column_name LIKE pattern
  18. 18. SQL JoinsThe JOIN keyword is used in an SQL statement to query datafrom two or more tables, based on a relationship betweencertain columns in these tables.Different SQL JOINs-JOIN: Return rows when there is at least one match in both tablesLEFT JOIN: Return all rows from the left table, even if there are no matches in the righttableRIGHT JOIN: Return all rows from the right table, even if there are no matches in theleft tableFULL JOIN: Return rows when there is a match in one of the tables
  19. 19. SQL INNER JOIN Keyword:-The INNER JOIN keywordreturn rows when there is atleast one match in bothtables.SQL INNER JOIN SyntaxSELECT column_name(s)FROM table_name1INNER JOIN table_name2ONtable_name1.column_name=table_name2.column_nameSELECT Persons.LastName,Persons.FirstName,Orders.OrderNoFROM PersonsINNER JOIN OrdersONPersons.P_Id=Orders.P_IdORDER BY Persons.LastName
  20. 20. SQL LEFT JOIN Keyword:-returns all rows from the lefttable (table_name1), even ifthere are no matches in theright table (table_name2).SQL LEFT JOIN SyntaxSELECT column_name(s)FROM table_name1LEFT JOIN table_name2ONtable_name1.column_name=table_name2.column_name SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo FROM Persons LEFT JOIN Orders ON Persons.P_Id=Orders.P_Id ORDER BY Persons.LastName
  21. 21. SQL RIGHT JOIN :-The RIGHT JOIN keywordreturns all the rows from theright table (table_name2),even if there are no matchesin the left table(table_name1).SQL RIGHT JOIN SyntaxSELECT column_name(s)FROM table_name1RIGHT JOIN table_name2ONtable_name1.column_name=table_name2.column_name SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo FROM Persons RIGHT JOIN Orders ON Persons.P_Id=Orders.P_Id ORDER BY Persons.LastName
  22. 22. SQL FULL JOIN :-The FULL JOIN keywordreturn rows when there is amatch in one of the tables.SQL FULL JOIN SyntaxSELECT column_name(s)FROM table_name1FULL JOIN table_name2ONtable_name1.column_name=table_name2.column_name SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo FROM Persons FULL JOIN Orders ON Persons.P_Id=Orders.P_Id ORDER BY Persons.LastName
  23. 23. VIEW:-A view is a virtual table based on the result-set of an SQLstatement.A view contains rows and columns, just like a real table. The fieldsin a view are fields from one or more real tables in the database.SQL CREATE VIEW Syntax:-CREATE VIEW view_name ASSELECT column_name(s)FROM table_nameWHERE condition
  24. 24. SQL Creating a View SQL Updating a View SQL Dropping a ViewIn SQL, a view is a virtual table You can update a view by You can delete a view with thebased on the result-set of an using the following syntax: DROP VIEW command.SQL statement. SQL CREATE OR REPLACE VIEW SQL DROP VIEW Syntax:-SQL CREATE VIEW Syntax:- Syntax:- DROP VIEW view_nameCREATE VIEW view_name AS CREATE OR REPLACE VIEWSELECT column_name(s) view_name ASFROM table_name SELECT column_name(s)WHERE condition FROM table_name WHERE conditionFor example, CREATE VIEW [Current ProductCREATE VIEW [Current Product List] ASList] AS SELECTSELECT ProductID,ProductName,CategProductID,ProductName oryFROM Products FROM ProductsWHERE Discontinued=No WHERE Discontinued=No
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×