Professional Documents
Culture Documents
Presentation On SQL
Presentation On SQL
Presentation On SQL
SQL
Not case-sensitive.
CLASSIFICATION
Select
Grant
Revoke
Creation of Database:
Database can be created by using the keyword
'CREATE DATABASE'.
Syntax: create database database_name;
Eg:
create database dbase;
Creation of Table:
Table can be created with the keyword
'CREATE TABLE'.
Syntax:
Eg:
Select statement:
JOINS IN SQL
Inner join
Full join
Self join.
Inner join:
Inner join selects all the fields that is getting
match with both the tables
Eg: select c.id, c.name, c.ph, o.o_id, o.o_quantity from
customer as c inner join orders as o on c.id = o.c_id;
Full join:
Full join selects all the fields from both the tables irrespective
of the condition and shows the null fields with the term 'null'.
Eg: select c.id, c.name, c.ph, o.o_id, o.o_quantity from
customer as c full join orders as o on c.id = o.c_id;
Self join:
FUNCTIONS IN SQL
Aggregate functions,
Scalar funtions.
AGGREGATE FUNCTIONS:
~ These functions will returns a single value based on the
opertations performed on the fields of the table.
~ Some of the aggregate functions are:
Numerals alone:
-> AVG()
-> SUM()
-> MAX()
-> MIN()
SCALAR FUNCTIONS:
These are another set of functions to process the values of the
fields.
UPPER()
LOWER()
ROUND()
DATE FUNCTIONS:
These are another set of functions to process the felds
containing the data type of date and time.
GETDATE()
DATEDIFF()
CONVERT()
OUTPUT OF DATE
FUNCTIONS
ALTER:
~ To add some fields to a existing table:
Syntax: ALTER TABLE table_name ADD COLUMN
data_type;
Eg:
Eg:
DELETE:
~ To delete a record from the table:
Syntax: DELETE FROM table_name where
CONDITION;
Eg:
DELETE FROM customer where id = 2;
~ To delete all the records of the table:
Syntax: DELETE FROM table_name;
Eg:
DELETE FROM customer;
(Note: if where condition is not mentioned, it will
delete entire contents of the table).
DROP:
~ To delete the schema of the table (i.e.) to delete the table,
we can go for 'DROP TABLE' keywords.
Syntax: DROP TABLE table_name;
Eg:
DROP TABLE customer;
~ To delete the database, we can go for
'DROP DATABASE' keywords.
Syntax: DROP DATABASE table_name;
Eg:
DROP DATABASE dbase;
COMMIT:
COMMIT;
ROLLBACK:
ROLLBACK | ROLLBACK TO
SAVEPOINT_NAME;
SAVEPOINT:
GRANT:
It is a command used to provide access or privileges on the
database objects to the users.
Syntax: GRANT privilege_name ON object_name
TO {user_name |PUBLIC |role_name}
[WITH GRANT OPTION];
Eg:
GRANT select ON customer TO PUBLIC;
REVOKE:
It removes user access rights or privileges to the database
objects.
Syntax: REVOKE privilege_name
ON object_name
FROM {user_name |PUBLIC |role_name}
Eg:
REVOKE select on customer from PUBLIC;
TUNING IN SQL
SQL can be made tuned by following some normal procedures.
Tuning is the process by which the optimum performance is
gained.
Some procedures are:
Always select the records using the WHERE clause.
Select only the required fields of the table.
Avoid function on the search conditions.
PIVOT:
It transform data from row-level to
columnar data.
STORED PROCEDURE
TRY AND CATCH
A TRYCATCH construct catches all execution errors.
ERROR MESSAGES.
TEMPORARY TABLES.
TRIGGERS
PIVOT:
SELECT * FROM ( SELECT o_id, o_name, c_id FROM
customer) as c
PIVOT ( SUM(o_quantity) FOR orders IN (name, age, ph,
city, postal) )AS piv ;
Eg of a coding:
CREATE PROCEDURE sp_emp
AS BEGIN
SELECT * FROM employ
END
BEGIN TRY
EXECUTE sp_emp
END TRY
BEGIN CATCH
IF ( error_number() = 208)
RAISEERROR ('this table is not exist', 0, 1)
ELSE SELECT error_message() AS errormessage
END CATCH
?
S
E
I
R
E
U
ANY Q
THANK YOU