You are on page 1of 13

PRACTICAL – 1

Demonstration of CREATE DATABASE, SHOW DATABASES and USE DATABASE


SQL commands.

(1) CREATE DATABASE


The CREATE DATABASE statement is used to create a new SQL database.

(2) SHOW DATABASE


The SHOW DATABASES statement is used to show existing SQL databases.

(3) USE DATABASE


The USE DATABASE statement is used to select the existing SQL databases.

1
PRACTICAL – 2
Demonstration of CREATE TABLE with NOT NULL, UNIQUE, PRIMARY KEY and
AUTO_INCREMENT Constraint and DESCRIBE TABLE SQL commands.

(1) CREATE TABLE


The CREATE TABLE statement is used to create a new table in a database.

(2) DESCRIBE TABLE


The DESCRIBE TABLE statement is used to describe existing table in a database.

2
PRACTICAL – 3
Demonstration of INSERT INTO SQL command
(1) INSERT INTO
The INSERT INTO statement is used to insert new records in a table.

INSERT INTO Syntax


It is possible to write the INSERT INTO statement in two ways:

1. Specify both the column names and the values to be inserted:

INSERT INTO table_name (column1, column2, column3, ...)


VALUES (value1, value2, value3, ...);

2. If you are adding values for all the columns of the table, you do not need to
specify the column names in the SQL query. However, make sure the order of the
values is in the same order as the columns in the table. Here, the INSERT
INTO syntax would be as follows:

INSERT INTO table_name


VALUES (value1, value2, value3, ...);

3
PRACTICAL – 4
Demonstration of SELECT SQL command with different methods.
(1) SELECT STATEMET
The SELECT statement is used to select data from a database.

The data returned is stored in a result table, called the result-set.

SELECT Syntax
SELECT column1, column2, ...
FROM table_name;

Here, column1, column2, ... are the field names of the table you want to select data from.

If you want to select all the fields available in the table, use the following syntax:

SELECT * FROM table_name;

4
PRACTICAL – 5
Demonstration of WHERE CLAUSE with SELECT SQL command.
(1) WHERE CLAUSE
The WHERE clause is used to filter records.

It is used to extract only those records that fulfil a specified condition.

WHERE CLAUSE Syntax


SELECT column1, column2, ...
FROM table_name
WHERE condition;

DEMO 1

DEMO 2

5
PRACTICAL – 6
Demonstration of the SQL AND, OR and NOT Operators.
The SQL AND, OR and NOT Operators

The WHERE clause can be combined with AND, OR, and NOT operators.

The AND and OR operators are used to filter records based on more than one condition:

 The AND operator displays a record if all the conditions separated by AND are TRUE.
 The OR operator displays a record if any of the conditions separated by OR is TRUE.

The NOT operator displays a record if the condition(s) is NOT TRUE.

DEMO TABLE

(1) AND Operator


AND Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;

6
(2) OR Operator
OR Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;

(3) NOT Operator


NOT Syntax
SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;

7
PRACTICAL – 7
Demonstration of the ALTER TABLE, ADD Column, DROP Column SQL
Commands.
(1) ALTER TABLE
The ALTER TABLE statement is used to add, delete, or modify columns in an
existing table.
The ALTER TABLE statement is also used to add and drop various constraints on an
existing table.

(2) ALTER TABLE -ADD Column


To add a column in a table, use the following syntax:

ALTER TABLE table_name


ADD column_name datatype;

(3) ALTER TABLE -DROP Column


To delete a column in a table, use the following syntax (notice that some database
systems don't allow deleting a column):

ALTER TABLE table_name


DROP COLUMN column_name;

8
PRACTICAL – 8
Demonstration of UPDATE SQL Command.
(1) UPDATE Statement
The UPDATE statement is used to modify the existing records in a table.

UPDATE Syntax
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

(2) Table After Updation.

9
PRACTICAL – 9
Demonstration of AGGREGATE FUNCTION such as SUM(), AVG(), MIN(),
MAX(), COUNT().
(1) AGGREGATE FUNCTION
An aggregate function in SQL performs a calculation on multiple values and returns a single
value.

DEMO Record

(2) SUM () FUNCTION


The SUM () function returns the total sum of a numeric column.

SUM () Syntax
SELECT SUM(column_name)
FROM table_name
WHERE condition;

10
(3) AVG () FUNCTION
The AVG () function returns the average value of a numeric column.

AVG () Syntax
SELECT AVG(column_name)
FROM table_name
WHERE condition;

(4) COUNT () FUNCTION


The COUNT () function returns the number of rows that matches a specified criterion.

COUNT () Syntax
SELECT COUNT(column_name)
FROM table_name
WHERE condition;

11
(5) MIN () FUNCTION
The MIN () function returns the smallest value of the selected column.

MIN () Syntax
SELECT MIN(column_name)
FROM table_name
WHERE condition;

(6) MAX () FUNCTION


The MAX () function returns the largest value of the selected column.

MAX () Syntax
SELECT MAX(column_name)
FROM table_name
WHERE condition;

12
PRACTICAL – 10
Demonstration of JOIN CLAUSE.
(1) JOIN CLAUSE
JOIN clause is used to combine rows from two or more tables, based on a related
column between them.

SYNTAX:

SELECT * FROM <Table1_NAME> JOIN <Table2_Name> ON Table1.column =

Table2.column WHERE <condition>;

Employee Table:

Department Table:

Natural Join by using Where Clause

13

You might also like