Sei sulla pagina 1di 10

Implementation of ddl commands

DDL (Data Definition Language)


DDL statements are used to alter/modify a database or table structure and schema. These
statements handle the design and storage of database objects.

CREATE – create a new Table, database, schema


ALTER – alter existing table, column description
DROP – delete existing objects from database

Most commonly used datatypes for Table columns


Here we have listed some of the most commonly used datatypes used for columns in
tables.

Datatype Use

INT used for columns which will store integer values.

FLOAT used for columns which will store float values.

DOUBLE used for columns which will store float values.

VARCHAR used for columns which will be used to store characters and integers, basically a
string.

CHAR used for columns which will store char values(single character).

DATE used for columns which will store date values.


TEXT used for columns which will store text which is generally long in length. For
example, if you create a table for storing profile information of a social networking
website, then for about me section you can have a column of type TEXT.

SQL: create command


create is a DDL SQL command used to create a table or a database in relational database
management system.

Creating a Database
To create a database in RDBMS, create command is used. Following is the syntax

Create table:
INSERT VALUE:

OUTPUT:
Select*from student;

SQL: Alter command


Alter command is used for altering the table structure, such as,

 to add a column to existing table


 to rename any existing column
 to change datatype of any column or to modify its size.
 to drop a column from the table.

 ALTER Command: Add a new Column


Using alter command we can add a column to any existing table. Following is the syntax,
In this table will add with name age and game column
Desc student;

Insertion the values:

Output:
ALTER TABLE WITH MODIFY:

Drop column:

TRUNCATE TABLE:
QUERIES:
Q1:
Create a table called emp with following structre.
Name type
Empno int
Ename varchar(15)
Job varchar(10)
Solution:

Q2:
Add a column experience to the emp table.
Experience numeric null allowed
Q3:
Modify the column width of the job field of emp table.
Solution:

Q4:
Create dep table with the following structure.
Name type
Deptno int;
Dname varchar(10);
Loc varchar(10);
Solution:
Q5:
Create the emp1 table with ename and empno,add
constraints to check the empno value while entering
empno>100.
Solution:

Q6:
Drop a column experience to the emp table.
Solution:
Q7:
Truncate the emp table and drop the dept table.

DATA MANIPULATION LANGUAGE:


DML commands are used for manipulating the data stored in the table and not the table
itself.
DML commands are not auto-committed. It means changes are not permanent to database,
they can be rolled back.

Command Description

insert to insert a new row

update to update existing row

delete to delete a row

merge merging two rows or two tables


creates a table and insert the values.

alter a table .

the update and delete command on the given table.