Saturday, 27 October 2012

Important SQL syntax for practical exam


i. Create table command
Syntax:
Create table TableName(attribute1 data type(size), attribute2 data type(size), attribute3 data type(size),……);
ii. Alter table command
a. Add Command
Syntax:
Alter table TableName
Add attribute data type(size);
b. Modify Command
Syntax :
Alter table TableName
Modify ( attribute data type(size));
iii. Drop Table Command
Syntax:
Drop table TableName;
iv. Truncate table command
Syntax:
Truncate table TableName;
v. Rename Table Command
Syntax:
Rename NewTableName, OldTableName ;
vi. Comment Command
Comment - Add comments to the data dictionary

2. DML(Data Manipulation Language):
i. Select Command
Syntax: select attribute1,attribute2 from TableName;
ii. Insert Command
Syntax :
insert into TableName values('Value1', 'value2', Value3);
iii.Update Command
Syntax:
Update TableNameattributeName=value
Where Condition;
iv. Delete Command
Syntax:
delete from Tablename where Condition;
1. The AVG() Function
Syntax:
Select Avg(Attribute) from TableName
2. TheCOUNT() Function

Syntax
SELECT COUNT(Attribute) FROM TableName

i. SQL COUNT(*) Syntax

SELECT COUNT(*) FROM table_name

ii. SQL COUNT(DISTINCT column_name) Syntax

SELECT COUNT(DISTINCT column_name) FROM table_name

4.The SUM() Function
SQL SUM() Syntax
SELECT SUM(column_name) FROM table_name
5.The MIN() Function
SQL MIN() Syntax
SELECT MIN(column_name) FROM table_name
6. The MAX() Function
SQL MAX() Syntax
SELECT MAX(column_name) FROM table_name
1. The Where Clause
Syntax:
SELECT column_name(s)
FROM table_name
WHERE column_name operator value
2. The Group by clause

Syntax:
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
3. The Having Clause
Syntax:
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value

4. The Order by clause
Syntax:
SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC

1. SQL INNER JOIN:

SQL INNER JOIN Syntax:
SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name;
.
2. SQL LEFT JOIN:
SQL LEFT JOIN Syntax:
SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name;

3. SQL RIGHT JOIN:
SQL RIGHT JOIN Syntax:
SELECT column_name(s)
FROM table_name1
RIGHT JOIN table_name2
ON table_name1.column_name=table_name2.column_name;

4. SQL FULL JOIN:
SQL FULL JOIN Syntax:
SELECT column_name(s)
FROM table_name1
FULL JOIN table_name2
ON table_name1.column_name=table_name2.column_name;


SQL CREATE VIEW Syntax:
CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition;



SQL Updating a View:
SQL CREATE OR REPLACE VIEW Syntax:
CREATE OR REPLACE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition:


SQL Dropping a View:
SQL DROP VIEW Syntax:
DROP VIEW view_name;




\

No comments:

Post a Comment