statements,joins and operators in sql by thanveer danish melayi(1)

23

Upload: muhammed-thanveer-danish-melayi

Post on 25-May-2015

203 views

Category:

Software


1 download

DESCRIPTION

enjoy.....

TRANSCRIPT

Page 1: Statements,joins and operators in sql by thanveer danish melayi(1)
Page 2: Statements,joins and operators in sql by thanveer danish melayi(1)

sql statements,operators and joins

typing speed:25

Muhammed Thanveer Melayi

[email protected]

Muhammed Thanveer Danish Melayi

Muhammed Thanveer M

Page 3: Statements,joins and operators in sql by thanveer danish melayi(1)

1.DML

2.DDL

3.DCL

• different type of statements

Page 4: Statements,joins and operators in sql by thanveer danish melayi(1)

DML

DML is abbreviation of Data Manipulation Language. It is used to retrieve, store, modify, delete, insert and update data in database.

Examples: SELECT, UPDATE, INSERT statements

Page 5: Statements,joins and operators in sql by thanveer danish melayi(1)

SYNTAX OF INSERT INTO

INSERT INTO table_name (column1,column2,column3,...)VALUES (value1,value2,value3,...);

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)VALUES ('Cardinal','Tom B. Erichsen','Skagen 21','Stavanger','4006','Norway');

Page 6: Statements,joins and operators in sql by thanveer danish melayi(1)

DDLDDL is abbreviation of Data Definition Language. It is used to create and modify the structure of database objects in database.Examples: CREATE, ALTER, DROP statements

Page 7: Statements,joins and operators in sql by thanveer danish melayi(1)

SYNTAX OF CREATE

CREATE TABLE table_name(column_name1 data_type(size),column_name2 data_type(size),column_name3 data_type(size),....);

CREATE TABLE Persons(PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255),City varchar(255));

Page 8: Statements,joins and operators in sql by thanveer danish melayi(1)

DCLDCL is abbreviation of Data Control Language. It is used to create roles, permissions, and referential integrity as well it is used to control access to database by securing it.Examples: GRANT, REVOKE statements

• GRANT - gives user's access privileges to database• REVOKE - withdraw access privileges given with the GRANT

command

Page 9: Statements,joins and operators in sql by thanveer danish melayi(1)

• privilege_name is the access right or privilege granted to the user. Some of the access rights are ALL, EXECUTE, and SELECT.

• object_name is the name of an database object like TABLE, VIEW, STORED PROC and SEQUENCE.

• user_name is the name of the user to whom an access right is being granted.

• PUBLIC is used to grant access rights to all users.• ROLES are a set of privileges grouped together.• WITH GRANT OPTION - allows a user to grant access rights to other

users.

GRANT privilege_name ON object_name TO {user_name |PUBLIC |role_name} [WITH GRANT OPTION];

Page 10: Statements,joins and operators in sql by thanveer danish melayi(1)

SYNTAX OF REVOKE

REVOKE privilege_name ON object_name

FROM {user_name |PUBLIC |role_name}

Page 11: Statements,joins and operators in sql by thanveer danish melayi(1)

example for grantgrant select --granting select privilegeon emp to public --you can give username at the place of public

example for revokerevoke select--removing select privilegeon empfrom public

Page 12: Statements,joins and operators in sql by thanveer danish melayi(1)

Joins

SQL JOIN clause is used to combine rows from two or more tables, based on a common field between them.

1.inner join2.full join3.left join4.right join

Page 13: Statements,joins and operators in sql by thanveer danish melayi(1)

SQL INNER JOIN Keyword

The INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns in both tables.

SQL INNER JOIN Syntax

SELECT column_name(s)FROM table1INNER JOIN table2ON table1.column_name=table2.column_name;

Page 14: Statements,joins and operators in sql by thanveer danish melayi(1)

SQL FULL OUTER JOIN KeywordThe FULL OUTER JOIN keyword returns all rows from the left table

(table1) and from the right table (table2).The FULL OUTER JOIN keyword combines the result of both LEFT and

RIGHT joins.

SQL FULL OUTER JOIN SyntaxSELECT column_name(s)

FROM table1FULL OUTER JOIN table2

ON table1.column_name=table2.column_name;

Page 15: Statements,joins and operators in sql by thanveer danish melayi(1)

SQL LEFT JOIN Keyword

The LEFT JOIN keyword returns all rows from the left table (table1), with the matching rows in the right table (table2). The result is NULL in the right side when there is no match.

SQL LEFT JOIN SyntaxSELECT column_name(s)FROM table1LEFT JOIN table2ON table1.column_name=table2.column_name;

Page 16: Statements,joins and operators in sql by thanveer danish melayi(1)

SQL RIGHT JOIN KeywordThe RIGHT JOIN keyword returns all rows from the right table (table2), with the matching rows in the left table (table1). The result is NULL in the left side when there is no match.

SQL RIGHT JOIN SyntaxSELECT column_name(s)FROM table1RIGHT JOIN table2ON table1.column_name=table2.column_name;

Page 17: Statements,joins and operators in sql by thanveer danish melayi(1)

OperatorsWhat is an Operator in SQL?An operator is a reserved word or a character used primarily in an SQL statement's WHERE clause to perform operation(s), such as comparisons and arithmetic operations.

Operators are used to specify conditions in an SQL statement and to serve as conjunctions for multiple conditions in a statement.

• Arithmetic operators (+,*,/,-...)• Comparison operators (=,!=,<>,>,<,>=.......)• Logical operators

Page 18: Statements,joins and operators in sql by thanveer danish melayi(1)

example for logical operatorsALLThe ALL operator is used to compare a value to all values in another value set.ANDThe AND operator allows the existence of multiple conditions in an SQL statement's WHERE clause.ANYThe ANY operator is used to compare a value to any applicable value in the list according to the condition.BETWEENThe BETWEEN operator is used to search for values that are within a set of values, given the minimum value and the maximum value.ORThe OR operator is used to combine multiple conditions in an SQL statement's WHERE clause.IS NULL

The NULL operator is used to compare a value with a NULL value.UNIQUEThe UNIQUE operator searches every row of a specified table for uniqueness (no duplicates).

for example....SELECT * FROM ProductsWHERE Price BETWEEN 10 AND 20;

Page 19: Statements,joins and operators in sql by thanveer danish melayi(1)

THANK YOU

Page 20: Statements,joins and operators in sql by thanveer danish melayi(1)

Disclaimer: This presentation is prepared by trainees of baabtra.com as a part of mentoring program. This is not official document of baabtra.com – Mentoring Partner

Page 21: Statements,joins and operators in sql by thanveer danish melayi(1)

Want to learn more about programming or Looking to become a good programmer?

Are you wasting time on searching so many contents online?

Do you want to learn things quickly?

Tired of spending huge amount of money to become a Software professional?

Do an online course @ baabtra.com

We put industry standards to practice. Our structured, activity based courses are so designed to make a quick, good software professional out of anybody who holds a passion for coding.

Page 22: Statements,joins and operators in sql by thanveer danish melayi(1)

Follow us @ twitter.com/baabtra

Like us @ facebook.com/baabtra

Subscribe to us @ youtube.com/baabtra

Become a follower @ slideshare.net/BaabtraMentoringPartner

Connect to us @ in.linkedin.com/in/baabtra

Give a feedback @ massbaab.com/baabtra

Thanks in advance

www.baabtra.com | www.massbaab.com |www.baabte.com

Page 23: Statements,joins and operators in sql by thanveer danish melayi(1)

Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

Cafit Square,Hilite Business Park,Near Pantheerankavu,Kozhikode

Start up VillageEranakulam,Kerala, India.Email: [email protected]

Contact Us