Professional Documents
Culture Documents
Data Definition Commands, Data Manipulation Commands For Inserting, Deleting, Updating and Retrieving Tables
Data Definition Commands, Data Manipulation Commands For Inserting, Deleting, Updating and Retrieving Tables
Data Definition Commands, Data Manipulation Commands For Inserting, Deleting, Updating and Retrieving Tables
Aim:
To create database and perform DML queries to retrieve information from the
database.
Different types of commands in SQL:
• DDL commands: - To create a database object.
• DML commands: - To manipulate data of a database objects.
Data Definition Language (DDL):
To specify the database schema.
DDL Commands:
• Create
• Alter
• Rename
• Drop
Creation of Table:
Creates a table with specified attributes and its data type along with
constraints.
Syntax:
CREATE TABLE TABLE_NAME(A1 D1, A2 D2, . . . AN DN)
Here Ai is the attribute of the table,
Di is the data type of the attribute
View the table structure:
Syntax:
desc r;
Code:
Desc student;
Syntax-
Code:
Add or delete or change the attribute and data type.It also can add or drop
Syntax:
Code:
Rename:
Syntax:
Code:
Syntax:
Drop table r;
Code:
1. Insertion of information
2. Retrieval of information
3. Deleting information
4. Modifying information
1. Procedural DMLs – requires a user to specify what data are needed and how
to get
those data.
Syntax-
Example :
1 row created.
1 row created.
1 row created.
1 row created.
UPDATE:
The UPDATE command updates some or all data values in a database. It can
update one or more records in a table. The UPDATE command specifies the
rows to be changed using the WHERE clause and the new data using the SET
keyword.
Syntax:
Example:
DELETE:
The DELETE command permanently removes one or more records from the
table. It removes the entire row, not individual fields of the row, so no field
argument is needed.
Syntax:
Example:
RESULT:
Thus the DDL, DML queries are executed successfully and the output is
verified
Ex no: Date: / / Dr. N.G.P Institute of Technology Reg no:710721205043
AIM:
PRIMARY KEY:
table. Each table should have a primary key, and each table can have only one
primary key.
Syntax:
UNIQUE:
The UNIQUE constraint uniquely identifies each record in a database table. The
Syntax:
To create a UNIQUE constraint when the table is already created, use the
following Syntax:
NOT NULL:
The NOT NULL constraint enforces a column to NOT accept NULL values.
The NOT NULL constraint enforces a field to always contain a value. The
DEFAULT:
The DEFAULT constraint is used to insert a default value into a column. The
CHECK:
The CHECK constraint is used to limit the value range that can be placed in a
certain values for this column. The following SQL creates a CHECK constraint
Example:
desc emp;
Table altered.
Table altered.
Table altered.
Table altered.
UNIQUE:
CHECK:
INSERT into
DELETE:
RESULT:
Thus, the constraints(PRIMARY KEY, UNIQUE KEY, CHECK, DEFAULT and NOT NULL) are add to the
table successfully and checked.
Ex no: Date: / / Dr. N.G.P Institute of Technology Reg no:710721205043
AIM:
integrity.
FOREIGN KEY:
The FOREIGN KEY constraint is used to prevent actions that would destroy
link between tables. The FOREIGN KEY constraint also prevents that invalid
data is inserted into the foreign key column, because it has to be one of the
values contained in the table it points to A FOREIGN KEY in one table points
SYNTAX:
EXAMPLE:
CREATE:
SQL> create table dept (d_no int primary key,d_name varchar(15),course_code int,course_title
varchar(15));
SQL> create table student1(id int,name varchar(15),d_id int,cgpa int,Foreign key(id) References
Dept(d_no));
Ex no: Date: / / Dr. N.G.P Institute of Technology Reg no:710721205043
INSERT:
1 row created.
1 row created.
1 row created.
ALTER:
Table altered.
RESULT:
Thus the table is created, foreign key constraint and incorporate referential integrityqueries are
added and checked.