2. Introduction to SQL:-
•Structured query language (SQL) is a
programming language for storing and
processing information in a relational
database.
•-> A relational database stores
information in tabular form, with
rows and columns representing
different data attributes and the
various relationships between the data
3. VARIOUS TYPES OF SQL COMMANDS:-
1.Data Definition Language(DDL)
2.Data Manipulation Language(DML)
3.Data Control Language(DCL)
4.Transaction Control Language(TCL)
5.Data Query Language(DCL)
5. Data Definition Language:-
• DDL (Data Definition Language) is a type of SQL
command used to define data structures and
modify data. These commands are used to create or
modify the tables in SQL.
• DDL COMMANDS:
1.Create
2.Alter
3.Truncate
4.Drop
5.Rename
6. 1.CREATE COMMAND:-
This command is used to create a new table in SQL. The
user has to give information like table name, column names,
and their datatypes.
SYNTAX:
CREATE TABLE table-name
(column1 data-type(size),
column2 data-type(size),
………………
column N data-type(size));
Ex: create table student( sno number(3),
sname varchar2(10),
saddress varchar2(10));
7. 2. ALTER COMMAND:-
•To change the structure of a table. This change could
be either modify an existing attribute or add a new
attribute.
• SYNTAX:
ALTER TABLE table-name {ADD / MODIFY} (column1
datatype1);
• Ex1: alter table stu add (sname varchar2(15));
• Ex2: alter table stu modify(sname char(6));
8. 3.TRUNCATE COMMAND:-
To remove all rows from a table we can use ‘truncate’
command.
•SYNTAX: TRUNCATE TABLE <tablename>
Ex: TRUNCATE table stu;
4.DROP COMMAND:-
The drop command can be used to drop a table.
SYNTAX: DROP TABLE table_name;
Ex: drop table stu;
9. 5.RENAME COMMAND:-
Rename command can be used to change the
name of an exiting table.
SYNTAX: RENAME <old name> to <new name>;
Ex: rename stu to student;
10. DATA MANIPULATION LANGUAGE:-
• A data manipulation language (DML) is a
computer programming language used for
adding , deleting, and modifying data in a
database.
•DML COMMANDS:
•1.Insert
•2.Update
•3.Delete
•4.Merge
11. INSERT COMMAND:-
The insert command is used to add rows to a table .
SYNTAX: insert into <tablename> values(a list of data values):
Ex: insert into student values (101, ‘brahmam’, ‘gnt’);
2.UPDATE COMMAND:-
An update statement changes the data of one or more records in a
table.
SYNTAX: update table_name SET column1 = value1, column2 =
value2,… WHERE condition;
Ex: UPDATE customers SET contact name = ‘Vishnu’, city = ‘viz’
WHERE customer id =1;
12. DELETE COMMAND:-
• The delete statement is used to remove one or more
records from a table.
• SYNTAX:
DELETE FROM table_name WHERE condition;
• Ex:
delete from customer where customer name = ‘Vishnu’;
13. DATA CONTROL LANGUAGE (DCL):-
• DCL commands are used to enforce database security in a
multiple user database environment.
• Only Database Administrator’s or owners of the database
object can provide /remove privileges on a database object.
• Two types of DCL commands. They are,
GRANT COMMAND
REVOKE COMMAND
14. GRANT COMMAND:-
• GRANT is a command used to provide access or privileges on
the database objects to the users.
• SYNTAX: grant privileges on <object name> to <user name>;
Ex:GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USE
R, ANOTHER_USER;
• REVOKE COMMAND:- The REVOKE command user access
rights or privileges to the database objects.
• SYNTAX: revoke privileges on <object name> from <user
name>;
• Ex:
REVOKE SELECT, UPDATE ON MY_TABLE FROM U
SER1, USER2;
15. TRANSACTION CONTROL LANGUAGE(TCL):-
• Transaction changes can be made permanent to a database
only if they are committed. A transaction executable
statements and end explicitly with their rollback or commit
statement and implicity.
Commit
Rollback
Save point
16. CON…
• COMMIT:- Commit command is used to save all the
transactions to the database.
• SYNTAX: COMMIT;
• Rollback:- Rollback command is used to undo transactions
that have not already been saved to the database.
• SYNTAX: ROLLBACK;
• Ex: delete from customers where age =25;
• ROLLBACK;
• SAVEPOINT:- It is used to roll the transaction back to a
certain point without rolling back the entire transaction.
• SYNTAX: SAVEPOINT savepoint_name;
17. DATA QUERY LANGUAGE(DQL):-DQL is used
to fetch the data from the database
• It uses only one command i.e, SELECT
• SELECT: This is the same as the projection
operation of relational algebra. It is used to
select the attribute based on the condition
described by WHERE clause.
1.SYNTAX:SELECT expressions
2.FROM TABLES
3.WHERE conditions;
Ex: SELECT emp_name
FROM employee
WHERE age > 20;