Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

SQL of DBMS PRESENTATION

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 15

DAVIM

DATABASE MANAGEMENT SYSTEM

NAME : VIVEK RAGHAV


COURCE: BSC (CS) 4rd SEM

Topic: SQL
Submitted to : Dr. MONICA KHATRI
Topic: SQL
INTRODUCTION
SQL (Structured Query Language) is a computer
language aimed to store, manipulate, and retrieve data
stored in relational databases.
IBM implemented the language, originally called Sequel,
as part of the System R project in the early 1970s..
The first commercial relational database was released by
Relational Software later becoming oracle.
The SQL language has several parts:
Data-definition language (DDL). Provides commands for
defining relation schemas, deleting relations, and
modifying relation schemas.
Interactive data-manipulation language (DML). It
includes also commands to insert tuples into, delete tuples
from, and modify tuples in the database.
View definition. includes commands for defining views.
Transaction control. includes commands for specifying
the beginning and ending of transactions.
DDL
DDL - Data Definition Language:
Statements used to define the database structure or
schema. Some examples:
CREATE - to create objects in the database
ALTER - alters the structure of the database
DROP - delete objects from the database
RENAME - rename an object
Data Manipulation Language
DML- Data Manipulation Language:
Statements used for managing data within
schema objects.
SELECT - retrieve data from the a database
INSERT - insert data into a table
UPDATE - updates existing data within a table
DELETE - deletes all records from a table, the
space for the records remain
CALL - call a PL/SQL or Java subprogram
Basic SQL Query
Select Clause :
1. select branch-name from loan Retain Duplicates
2. select distinct branch-name from loan Remove
duplicates
3. select all branch-name from loan Retain Duplicates
Where Clause :
1. select loan-number from loan where branch-name =
’Perryridge’ and amount > 1200
From Clause :
select customer-name, borrower.loan-number, amount
from borrower, loan where borrower.loan-number =
loan.loan-number
Basic SQL Query
Rename Operation :
select customer-name, borrower.loan-number as loan-id, amount from borrower, loan where
borrower.loannumber
= loan.loan-number
Tuple variables :
select customer-name, T.loan-number, S.amount from borrower as T, loan as S where T.loan-
number = S.loannumber Tuple variables are most useful for comparing two tuples in the same
relation.
String Operations :
select customer-name from customer where customerstreet like ’%Main%’
SQL INSERT, UPDATE, DELETE
Query with Example.

The data modification clauses in SQL


are INSERT, UPDATE, and DELETE
statements. It is used for inserting new
rows, updating existing values, or
deleting rows from the database.
1.SQL INSERT
SQLite INSERT is used to insert records into a specified table of the database. you have to use
the 'INSERT' clause. The INSERT clause syntax is as follows:

•After the INSERT clause, you should state which table you need to insert the
values into.
•After the table name you write the list of columns, you want to insert the values
into.
•You can ignore the columns name and don't write to them.
•If you don't write the columns name, the values will be inserted into all the
columns found in the table with the same order, the columns are defined in the
table.
•After the VALUES clause, you should list the values to be inserted.
•Each INSERT clause inserts only one row. If you want to insert multiple rows, you
should write multiple INSERT clauses, one for each row.
SQL Insert Example
INSERT INTO Students(StudentId, StudentName, DepartmentId, DateOfBirth)
VALUES(11, 'Ahmad', 4, '1997-10-12');
INSERT INTO Students VALUES(12, 'Aly', 4, '1996-10-12');

This should run successfully and there is no output for this:

This will insert two students:


•The first student with StudentId=11, StudentName = Ahmad,
DepartmentId = 4, and DateOfBirth = 1997-10-12.
•The second student with StudentId=12, StudentName = Aly,
DepartmentId = 4, and DateOfBirth = 1996-10-12'.
2.SQL UPDATE
SQL UPDATE Query is used to modifying the existing records in a
table. You can use WHERE clause with UPDATE query to update
selected rows. The UPDATE clause updates a table by changing a
value for a specific column. The following is the syntax of the
UPDATE clause:
As following:
•After the "update clause", you should write the table name to
update.
•You have to write "SET clause" which is used to write the column
name to update and the value to be updated.
•You can update more than one column. You can use a comma
between each line.
•You can specify a WHERE clause to specify some rows only. Only the
rows that the expression evaluates to true are updated. If you didn't
specify a WHERE clause, all the rows will be updated.
SQLite Update Example
In the following UPDATE statement, we will update the DepartmentId for the Student
with StudentId = 6 to be 3:
UPDATE Students
SET DepartmentId = 3
WHERE StudentId = 6;

This should run successfully and you shouldn't get any output:

In the UPDATE clause, we specified that we want to update the


table Students.
•In the WHERE clause, we filtered all the students to select only the
row for StudentId = 6.
•The SET clause will update the value of the Department Id for the
selected students to be 3.
3.SQL Delete
SQLite DELETE query is used to remove existing records from a
specified table. You can use the WHERE clause with DELETE queries
to delete the selected rows.

DELETE clause has the following syntax:


•You have to write a table name after the DELETE FROM clause, from which you want
to delete records. (Note: that the DELETE clause is used to delete some records from
a table or delete all the records and it won't delete the table itself. However,
the DROP clause is used to delete the entire table with all the records on it.)
•If you write the DELETE clause like this "DELETE FROM guru", this will delete all the
records from the table "guru".
•You can specify a WHERE condition with an expression if you want to delete some
specific rows. Only the rows for which the expression evaluates to true will be
deleted. For example, "DELETE FROM guru WHERE id > 5" – this will delete only the
records that have id larger than 5.
DELETE EXAMPLE
In the following statement, we will delete two students with StudentId 11 and 12:

DELETE FROM Students WHERE StudentId = 11 OR StudentId = 12;

The expression "StudentId = 11 OR StudentId = 12" will be true for


only students with Ids 11 and 12. So the DELETE clause will be applied
on both and will delete them only.
This command should run successfully and you shouldn't get any
output as following:
This is all about the SQL of DBMS

Thank you

You might also like