Alter Table

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

OBJECT-Write a query in sql to implement altertable with all it’s components.

The ALTER TABLE Statement


The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.

SQL ALTER TABLE Syntax


To add a column in a table, use the following syntax:
ALTER TABLE table_name
ADD column_name datatype
To delete a column in a table, use the following syntax (notice that some database systems don't allow deleting a
column):
ALTER TABLE table_name
DROP COLUMN column_name
To change the data type of a column in a table, use the following syntax:
ALTER TABLE table_name
ALTER COLUMN column_name datatype
CODE-:
SQL>Alter table kcs
SQL>Add btch(12);
SQL> select*from kcs;

NAME SNAME RLNO CITY PINCODE BAL BTCH


---------- ---------- ---------- ---------- ---------- --------------- -------------- ------------- --------
khawar nawab 801710021 bijnor 246701 15000
abishek srivastav 801710001 devariya 347212 12000
mohd wasi 801710021 bijnor 246701 10000
pushpank kaushik 701710040 haldaur 246731 15000
sachin sharma 801710042 bijnor 246701 12000
mohd azhar 801710009 muradngr 113115 10000
mohd shariq 801710024 pursanda 246701 10000
sachin verma 801710043 haldaur 246731 12000
gaurav kumar 801710014 chandpur 246733 15000
mohit kumar 801710025 badhapur 246744 12000
mohit malik 801710027 bijnor 246701 12000
11 rows selected.

SQL> alter table kcs


2 drop column btch;
Table altered.
SQL> select*from kcs;
NAME SNAME RLNO CITY PINCODE BAL
---------- ---------- ---------- ---------- ---------- --------------- -------------- ------------- --------
khawar nawab 801710021 bijnor 246701 15000
abishek srivastav 801710001 devariya 347212 12000
mohd wasi 801710021 bijnor 246701 10000
pushpank kaushik 701710040 haldaur 246731 15000
sachin sharma 801710042 bijnor 246701 12000
mohd azhar 801710009 muradngr 113115 10000
mohd shariq 801710024 pursanda 246701 10000
sachin verma 801710043 haldaur 246731 12000
gaurav kumar 801710014 chandpur 246733 15000
mohit kumar 801710025 badhapur 246744 12000
mohit malik 801710027 bijnor 246701 12000
11 rows selected.
SQL> describe kcs
Name Null? Type
----------------------------------------- -------- ----------------------------
NAME CHAR(10)
SNAME CHAR(10)
RLNO NUMBER(10)
CITY CHAR(10)
PINCODE NUMBER(7)
BAL NUMBER(12)
SQL> alter table kcs
2 modify(bal number(15));

Table altered.

SQL> describe kcs;


Name Null? Type
----------------------------------------- -------- ----------------------------
NAME CHAR(10)
SNAME CHAR(10)
RLNO NUMBER(10)
CITY CHAR(10)
PINCODE NUMBER(7)
BAL NUMBER(15)

You might also like