0% found this document useful (0 votes)
84 views2 pages

Alter Table

The ALTER TABLE statement in SQL is used to modify the structure of existing tables. It allows you to add, delete, or modify columns. The syntax for adding a column uses ALTER TABLE and specifies the table name and new column name and data type. The syntax for dropping a column uses ALTER TABLE, specifies the table name and column to drop. The syntax for modifying a column's data type uses ALTER TABLE and specifies the table, column, and new data type.

Uploaded by

Khawar Nawab
Copyright
© Attribution Non-Commercial (BY-NC)
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)
84 views2 pages

Alter Table

The ALTER TABLE statement in SQL is used to modify the structure of existing tables. It allows you to add, delete, or modify columns. The syntax for adding a column uses ALTER TABLE and specifies the table name and new column name and data type. The syntax for dropping a column uses ALTER TABLE, specifies the table name and column to drop. The syntax for modifying a column's data type uses ALTER TABLE and specifies the table, column, and new data type.

Uploaded by

Khawar Nawab
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 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