DBMS 2
DBMS 2
Aim : Queries to Retrieve and Change Data: Select, Insert, Delete and Update.
Description :
Select : The SELECT statement is used to select data from a database. The data returned
is stored in a result table, called the result-set.
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;
SELECT Columns
The following SQL statement selects the "deptno", "ename", and "job" columns from the
"empl" table:
Reg. no.:
SELECT *
The following SQL statement selects ALL the columns from the "Customers" table:
The following SQL statement selects only ename from the "empl" table:
INSERT : The INSERT INTO statement is used to insert new records in a table.
It is possible to write the INSERT INTO statement in two ways:
Specify both the column names and the values to be inserted:
Syntax :
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
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:
Syntax :
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
Reg. no.:
Here is an example of inserting data into a table names empl:
UPDATE : The UPDATE statement is used to modify the existing records in a table.
Syntax :
UPDATE table_name
SET column1 = value1, column2 = value2,
WHERE condition;
Reg. no.:
Reg. no.:
DELETE :
The DELETE statement is used to delete existing records in a table.
Syntax :
DELETE FROM table_name WHERE condition;
Note: Be careful when deleting records in a table! Notice the WHERE clause in the
DELETE statement. The WHERE clause specifies which record(s) should be deleted. If
you omit the WHERE clause, all records in the table will be deleted!
1 row deleted.
Reg. no.: