SQL stands for Structured Query Language.
SQL is a database management language for relational databases.
SQL lets you access and manipulate databases.
2. SQL stands for Structured Query Language.
SQL is a database management language for relational databases.
SQL lets you access and manipulate databases.
SQL queries are not case sensitive. (SELECT = select)
3. Data Manipulation Language (DML) is used to add, update or
delete data . Examples: INSERT, DELETE and UPDATE.
Data Definition Language (DDL) is used for managing tables and
index structures. Examples: CREATE, ALTER,TRUNCATE and
DROP.
Data Control Language (DCL) is used to assign and revoke
database rights and permissions. Its main statements are GRANT
and REVOKE.
4. SELECT - extracts data from a database
UPDATE - updates data in a database
DELETE - deletes data from a database
INSERT INTO - inserts new data into a database
CREATETABLE - creates a new table
ALTERTABLE - modifies a table
DROPTABLE - deletes a table
5. The CREATETABLE statement is used to create a table in a
database.
CREATETABLE table_name(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
....
);
E.g. : CREATETABLE People(
ID int,
FirstName varchar(255),
LastName varchar(255),
);
6. The INSERT INTO statement is used to insert new records in a
table.
INSERT INTO table_name
(column1, column2,..)
VALUES ( Value1,Value2,…)
E.g. : INSERT INTO Customers(ID, FirstName, LastName)
VALUES (1,’Abhi’,’Gautam’)
7. The UPDATE statement is used to update existing records in a
table.
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
E.g. : UPDATE Customers
SET FirstName =‘Abhishek'
WHERE ID=1;
8. The DELETE statement is used to delete records in a table.
DELETE FROM table_name
WHERE some_column=some_value;
E.g. : DELETE FROM Customers
WHERE FirstName =‘Abhishek'
9. The ALTERTABLE statement is used to add, delete, or modify columns
in an existing table.
ALTERTABLE table_name
ADD column_name datatype
ALTERTABLE table_name
DROP COLUMN column_name
ALTERTABLE table_name
ALTER COLUMN column_name datatype
10. The DROPTABLE statement is used to delete an existing table.
DROPTABLETable_Name;
E.g. : DROPTABLE Customers;
11. SELECT * FROM table_name;
SELECT column_name,column_name
FROM table_name;
E.g. : SELECT * FROM Customers;
SELECT FirstName FROM Customers;
12. The SELECT DISTINCT statement is used to return only distinct
(different) values.
SELECT DISTINCT column_name,column_name
FROM table_name;
E.g. : SELECT DISTINCT FirstName FROM Customers;
13. The WHERE clause is used to filter records.
SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;
E.g. : SELECT DISTINCT FirstName FROM People
WHERE ID=5;
14. The AND operator displays a record if both the first condition AND the
second condition are true.
The OR operator displays a record if either the first condition OR the
second condition is true.
E.g. : SELECT * FROM Customers
WHERE FirstName=‘Abhishek'
AND LastName=‘Gautam';
SELECT * FROM Customers
WHERE FirstName=‘Abhishek'
OR LastName=‘Gautam';
15. GROUP BY clause is used to group the result based on the Column
named in the GROUP BY clause.
SELECT Col_list FROM Table_Name
WHERE where_condition
GROUP BY col_list ;
16. ORDER BY clause is used to organize the result in ascending or
descending order based on the Column named in the ORDER BY
clause. Ascending order segregation is by default, to organize the
result in descending order we have to use DESC clause.
SELECT Col_list FROMTable_Name WHERE where_condition
GROUP BY col_list
ORDER BY col_name DESC ;
17. JOIN clause is used to get result from two or more table which have
a common column.
SELECT a.col_name,b.col_name FROM
Table1_Name a
JOIN Table2_Name b
ON a.col_Name=b.col_Name;
INNER JOIN: Returns all rows when there is at least one match in BOTH
tables
LEFT JOIN: Return all rows from the left table, and the matched rows
from the right table
RIGHT JOIN: Return all rows from the right table, and the matched rows
from the left table
FULL JOIN: Return all rows when there is a match inONE of the tables
18.
19. User Defined functions
Built-in functions
COUNT()
MAX()
REPLACE()
SUBSTRING()