Advertisement

SQL Commands ALTER, DROP, UPDATE || Lesson 26 || DBMS || Learning Monkey ||

SQL Commands ALTER, DROP, UPDATE || Lesson 26 || DBMS || Learning Monkey || SQL Commands ALTER, DROP, UPDATE

Link for website:

Here we will understand SQL Commands ALTER, DROP, UPDATE.

In our discussion on Understanding SQL Commands DDL, DML, TCL, DCL, DQL clearly understood the categories of SQL Commands.

Now we will understand some of the ALTER, DROP, UPDATE Commands.

As we have discussed the ALTER and DROP are categorized under DDL (Data Definition Language) and UPDATE is categorized under DML (Data Manipulation Language).
ALTER, DROP, UPDATE Commands:

ALTER and DROP are DDL Commands. DDL Commands are used to change the structure of the table in the database.
ALTER Command:

In our previous discussions, we have already covered how to add constraints using ALTER Command.


Now we will cover how to alter a table by adding a column, modify the data type of a column, and drop a column from the table.
To this table, we would like to add a new column by name address and data type varchar(15).

SQL Statement to ADD COLUMN:

ALTER TABLE student ADD address varchar(15);
SQL Statement to MODIFY DATATYPE of a Column:

ALTER TABLE student MODIFY address varchar(10);

After executing the statement the data type size of the address column has been changed to 10.


SQL Statement to DROP COLUMN from the Table:

ALTER TABLE student DROP COLUMN address;
UPDATE Command:

Update is a DML Command.

DML Commands are used to manipulate the data in the table.

SQL Statement to UPDATE Without and With WHERE Clause:

UPDATE student SET stuname = ‘C’, Branch = ‘CSE’ WHERE stunum = 1;

In the above command SET is a keyword and WHERE is a Clause.

If the WHERE Condition (UPDATE student SET stuname = ‘C’, Branch = ‘CSE’;) is not provided in the command then the names and the branches of all the students will be updated to C and CSE



Now considering the WHERE Condition (UPDATE student SET stuname = ‘C’, Branch = ‘CSE’ WHERE stunum = 1;)

The update is done only in the rows where the condition stunum = 1 is true. In our case, it is the first row.
DROP TABLE:

SQL Statement to DROP TABLE from the Database:

DROP TABLE student;

With the execution of the above command, the Student table will be deleted from the database.

ALTER Command,DROP Command,UPDATE Command,DBMS,GATE CSE,GATE DBMS,DDL,DML,TCL,DCL,DQL,Learning Monkey,Placements Preparation,

Post a Comment

0 Comments