You are on page 1of 4

EXPERIMENT-3

3. Queries to Retrieve and Change Data: Select, Insert,


Delete, and Update.
Objective : To understand the different issues involved in the design and
implementation of a database system and To understand and use data
manipulation language to query, update, and manage a database.

Theory : SQL Commands are divided into 5 sub languages.

SQL CREATE Statement


The SQL CREATE TABLE statement allows you to create and define a table.

Syntax
The syntax for the CREATE TABLE statement in SQL is:
CREATE TABLE table_name 
(column_name1 datatype, 
column_name2 datatype, 
... column_nameN datatype 
);

 table_name - is the name of the table.


 column_name1, column_name2.... - is the name of the columns
 datatype - is the datatype for the column like char, date, number etc.

SQL INSERT Statement


The SQL INSERT statement is used to insert a one or more records into a table.
1. Only values: First method is to specify only the value of data to be inserted
without the column names.

INSERT INTO table_name VALUES (value1, value2, value3,…);


table_name: name of the table.
value1, value2,.. : value of first column, second column,… for the
new record
2. Column names and values both: In the second method we will specify both
the columns which we want to fill and their corresponding values as shown
below:

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


( value1, value2, value3,..);
table_name: name of the table.
column1: name of first column, second column …
value1, value2, value3 : value of first column, second column,… for
the new record
SQL SELECT Statement

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;

SQL WHERE Clause

The WHERE clause is used to filter records.The WHERE clause is used to extract
only those records that fulfill a specified condition.

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

SQL UPDATE Statement

The UPDATE statement is used to modify the existing records in a table.

Syntax
UPDATE table_name
SET column1 = value1, column2 = value2, ... columnN = valueN
WHERE [condition];

DELETE Statement
The SQL DELETE statement is a used to delete a one or more records from a
table.

Syntax
The syntax for the DELETE statement in SQL is:
DELETE FROM table
[WHERE conditions];

Parameters or Arguments
table

The table that you wish to delete records from.

WHERE conditions

Optional. The conditions that must be met for the records to be deleted. If no
conditions are provided, all records in the table will be deleted.

PRACTICE ON SQL COMMANDS:

-----Write down observation

You might also like