Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

EXNO:1 AIM:

DDL&DML COMMAND

To write a program query in MySQL DDL Create Alter Drop

DML Insert Update Delete Select

SYNTAX: Create: create table <table_name> (<attribute_name> <datatype>) Alter: alter table <table_name> add (<attribute_name> <datatype>) Drop: alter table <table_name> drop <attribute_name> Insert : insert into <table_name> values(<value1>,<value2>.<valuen>) Update : update table <table_name> values set <attribute_name>=<expression> Delete : Delete from <table_name> where <attribute_name>=<value> Select : Select * from <table_name>

QUERIES: mysql> create table marktab(name varchar(30),mark1 int,mark2 int); Query OK, 0 rows affected (0.08 sec)

mysql> insert into marktab values('anand',80,80),('saga',70,90);

Query OK, 2 rows affected (0.06 sec) Records: 2 Duplicates: 0 Warnings: 0

mysql> select * from marktab; +-------+-------+-------+ | name | mark1 | mark2 | +-------+-------+-------+ | anand | | saga | 80 | 70 | 80 | 90 |

+-------+-------+-------+ 2 rows in set (0.00 sec)

mysql> update marktab set mark2=90 where name='anand'; Query OK, 1 row affected (0.05 sec) Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from marktab; +-------+-------+-------+ | name | mark1 | mark2 | +-------+-------+-------+ | anand | | saga | 80 | 70 | 90 | 90 |

+-------+-------+-------+ 2 rows in set (0.00 sec)

mysql> alter table marktab add(total int);

Query OK, 2 rows affected (0.13 sec) Records: 2 Duplicates: 0 Warnings: 0

mysql> select * from marktab; +-------+-------+-------+-------+ | name | mark1 | mark2 | total | +-------+-------+-------+-------+ | anand | | saga | 80 | 70 | 90 | NULL | 90 | NULL |

+-------+-------+-------+-------+ 2 rows in set (0.00 sec)

mysql> delete from marktab where name='anand'; Query OK, 1 row affected (0.00 sec)

mysql> select * from marktab; +------+-------+-------+-------+ | name | mark1 | mark2 | total | +------+-------+-------+-------+ | saga | 70 | 90 | NULL |

+------+-------+-------+-------+ 1 row in set (0.00 sec)

mysql> drop table marktab; Query OK, 0 rows affected (0.06 sec) RESULT:

The above SQL commands are successfully entered & verified.

You might also like