Download DDL,DCL and DML

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Oracle Database wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

IMDb wikipedia , lookup

Open Database Connectivity wikipedia , lookup

SQL wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Database wikipedia , lookup

Concurrency control wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

PL/SQL wikipedia , lookup

Ingres (database) wikipedia , lookup

Functional Database Model wikipedia , lookup

Clusterpoint wikipedia , lookup

ContactPoint wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Transcript
DDL, DML AND DCL STATEMENTS
Aim:
To execute and verify various data definition , manipulation and control
statements in SQL.
Theory:
Structured Query Language includes:
1) DDL – Data Definition Language
2) DML– Data Manipulation Language
3) DCL – Data Control Language
1) Data Definition Language (DDL):
It is a subset of SQL that is used to define, describe and change the structure of
database.
It can change and record the information in Data Dictionary
DDL Statements:
1. Create Table
2. Desc Table
3. Alter Table
4. Drop Table
1. Create Table:

This command enables the users to create their own tables.

The name of the tables can be given by the users and it should begin withan
alphabet followed by a set of alphabets or numerals or special characters like
‘_’

The column names in the table must be unique

The columns may have constraints like PRIMARY KEY, UNIQUE,
FOREIGN KEY,DEFAULT, CHECK etc.,
Primary Key:
This constraint can be set for the field that acts as an identifier
A field with primary key constraint will not accept “duplicate” and NULL
values
Unique:
A field with unique constraint may have NULL values but all other values
should not be duplicated.
Foreign Key:
A foreign key field of one table may refer the primary key field of another
table in order to maintain the consistency between them.
Default:
This constraint assigns a default value to particular field if that field is
skipped during insertion.
Check:
This constraint checks whether the value of that field satisfies given
condition. It will not allow the field values that does not satisfy the
condition specified by the check constraint.
Not Null:
A field with this constraint will not accept NULL values.
Syntax to Create Table:
Create table <table_name>
(
<column-name1> <datatype1> [constraints],
<column-name2> <datatype2> [constraints],
.
.
.
.
.
<column-name N> <datatype-n> );
2. Desc Table:
This command is used to describe the structure of database.
Syntax:
Desc <tablename>
3. Alter Table:
This command is used to add a new column to existing database and also to
modify an existing column in the database
Syntax:
ALTER TABLE <table-name>
ADD | MODIFY (< col-name> <data-type> )
< constraints >];
4. Drop Table:
This command is used to remove the entire schema(structure) of the
database
Syntax:
DROP TABLE <table-name> ;
2.Data Manipulation Language : (DML)
DML is a subset of SQL commands and are used to manipulate the database.
DML Statements:
1.
2.
3.
4.
Insert
Update
Delete
Select
1.Insert :
This command is used to add new records to the database.
Syntax :
INSERT INTO <table-name> [list of columns]
VALUES (list of values) ;
2.Update:

This command is used to change the already existing records in the database.

A simple update statements performs changes in all the records

Update statement with where condition changes only the records that satisfies
given where condition.
UPDATE <table-name> SET <col-name> =
<new-value> [, <col-name> = <new-value>]
[WHERE <condition>];
3. Delete:

This command is used to remove the records from table.

A simple delete command removes all the records in the table

Delete command with where clause removes only the records that satisfies given
where condition
DELETE FROM <table-name>
[WHERE <condition>];
4.Select:

This command is used to retrive a single record or set of records from a table(or
set of tables)

If where clause is specified it selects a set of records that satisfies given condition

If column names are specified, it selects only that columns otherwise a ‘ * ‘
SELECT * | <column-names FROM <table-name>
[WHERE <condition>];
3.Data Control Languages(DCL):
DCL is used to control the database access among multiple users.
Various DCL statements are:
1. Grant
2. Revoke
3. Role
4. Commit
5. Save Point
6. Rollback
1.Grant:
Grant command is used to create users and to grant access to the database.
Syntax:
GRANT <database_privilege> TO
<user-name> IDENTIFIED BY <password>
2.Revoke:
The DBA can revoke database privileges from any user using this command.
Syntax:
REVOKE <database_privilege>
FROM
<user-name>
3.Role:

This is used to simplify the administrative tasks involved in the
management of privileges

Role is a collection of related system privileges

Role can be granted to users or to other role(s)
Syntax to Create Role:
CREATE ROLE <role-name>
IDENTIFIED BY <password>
Syntax to Grant Role:
GRANT <role-name> TO <user-name>
Syntax to Set Role:
SET ROLE <rolename>
4.Commit:

This is used to make the changes to data (insert, delete or update)
permanent
 Commit can be done automatically using the AUTOCOMMIT command
Syntax to set commit:
SET AUTOCOMMIT ON
Syntax to reset commit:
SET AUTOCOMMIT OFF
Syntax to save updation:
COMMIT
5.Save Point:
This identifies a point in transaction to shich one can later rollback with Rollback
statement
SAVEPOINT <save_point_name>
6.Rollback:
It is used to discard parts or all the work the user has done in the current
transaction
ROLLBACK <save_point_name>