2. Agenda:
• Introduction
• Datatypes of SQL
• Operators of SQL
• Basic Database Concepts
• Processing capabilities of SQL
• Joins and its types
• Aggregate functions
• Stored procedures
• Index
• Triggers
3. Introduction:
• SQL is a non procedural language that is used to create,
manipulate and process the database.
Characteristics of SQL:
• Easy to learn and use.
• Large volume of DB can be handled easily.
4. Datatypes of SQL:
• Like programming languages, datatypes are also available in SQL
• Most commonly used types:
Int
Date
Long
Number
varchar/ nvarchar
6. Basic Database concepts:
• Data: -Raw facts and figures useful to an organization.
-Cannot take decisions on basis of data.
• Field : -Set of characters
• Record: -Collection of fields
• Primary key: -Uniquely identifies the records
-Never allow NULL and duplicates
• Foreign key: -Referential integrity
7. Processing capabilities of SQL
• Data Definition Language (DDL)
• Views
• Data Manipulation Language (DML)
• Data Control Language (DCL)
• Transaction Control Language (TCL)
8. Processing capabilities of SQL
Data Definition Language (DDL):
Common DDL statements are CREATE, ALTER, DROP.
CREATE – To create new DB, table, index, view etc..,
ALTER - To alter the table, DB etc..,
DROP - To delete objects from DB.
View:
- View is a kind of virtual table.
- It contains rows and columns like a real table.
- We can create a view by selecting fields.
9. Processing capabilities of SQL
Data Manipulation Language (DML):
- To manipulate the database objects
- Query the DB for information retrieval
- Common DML statements are
SELECT
INSERT
DELETE
UPDATE
10. Processing capabilities of SQL
Data Control Language(DCL):
- Controlling access to the data
- Common DCL commands are GRANT , REVOKE
Transaction Control Language (TCL):
- Control the transaction in DB system
- Common TCL commands are COMMIT, ROLLBACK
11. Joins and its types
• Used to combine rows from two or more tables, based on a
related column between them.
Types:
- Inner Join
- Left Join
- Right Join
- Full Join
- Self Join
13. Stored procedures
• It stored as an object in the database server.
• The code can be reused over and over again and then just call it
to execute it.
Syntax:
CREATE PROCEDURE procedure_name // Create stored proc.
AS
sql_statement
GO;
EXEC procedure_name; //Execute a stored procedure
14. Index
• Used to retrieve data from the DB very fast.
• Users cannot see the indexes, they are just used to speed up
searches/queries.
Syntax:
CREATE INDEX index_name
ON table_name (column1, column2, ...);
Types:
Clustered index - rows are stored physically on the disk in the
same order
Non Clustered index - second list that has pointers to the
physical rows.
15. Triggers
• Special kind of Stored procedure
• Automatically invokes whenever a DML and DDL events in DB
occurs
Syntax:
create trigger deep
on emp
for
insert,update,delete
as
print'you can not insert,update and delete this table i'
rollback;