0% found this document useful (0 votes)
2 views

Program 8

The document demonstrates the differences between the ALTER and UPDATE SQL commands. ALTER is used to modify the structure of a table, such as adding, dropping, renaming columns, or changing data types, while UPDATE is used to change existing records within a table. Examples of both commands are provided to illustrate their functionalities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Program 8

The document demonstrates the differences between the ALTER and UPDATE SQL commands. ALTER is used to modify the structure of a table, such as adding, dropping, renaming columns, or changing data types, while UPDATE is used to change existing records within a table. Examples of both commands are provided to illustrate their functionalities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Program 8

Write a program to show the difference between alter and update


command.
1. ALTER TABLE
a. ALTER TABLE - ADD Column
 mysql> alter table bca
-> add column last_name varchar(30);
Query OK, 0 rows affected (0.18 sec)
Records: 0 Duplicates: 0 Warnings: 0

 mysql> select * from bca;

b. ALTER TABLE - DROP COLUMN


 mysql> alter table bca
-> drop column marks;
Query OK, 0 rows affected (0.06 sec)
Records: 0 Duplicates: 0 Warnings: 0

 mysql> select * from bca;


c. ALTER TABLE - RENAME COLUMN
 mysql> alter table bca
-> rename column name to first_name;
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0

 mysql> select * from bca;

d. ALTER TABLE - ALTER/MODIFY DATATYPE


 mysql> alter table bca
-> modify column roll_no varchar(12);
Query OK, 5 rows affected (0.14 sec)
Records: 5 Duplicates: 0 Warnings: 0

 mysql> desc bca;


1. Update with set:
 mysql> update bca
-> set marks="399"
-> where name="mahinder";
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0

Before update command After update command

ALTER Command is used to add, delete, modify the attributes of the


relations (tables) in the database. UPDATE Command is used to
update existing records in a database.

You might also like