How to use ALTER command in SQL

How to use ALTER command in SQL




Create Table XX_EMP_TL
(
EMP_ID  NUMBER,
EMP_NAME VARCHAR2(100),
EMP_DOB  DATE,
EMP_GRADE  CHAR
)

Desc XX_EMP_TL

select * from XX_EMP_TL

--====================
--ALter Table   - ADD Single column
--====================

ALTER TABLE XX_EMP_TL ADD Date_Of_Joining DATE

select * from XX_EMP_TL

Desc  XX_EMP_TL


--====================
--ALter Table   - ADD Multiple column
--====================

ALTER TABLE XX_EMP_TL ADD (ATTRIBUTE1 NUMBER, ATTRIBUTE2 varchar2(100), ATTRIBUTE3 Date)


select * from XX_EMP_TL

desc XX_EMP_TL



--====================
--ALter Table   - modify any column like number to varchar
--====================

alter table XX_EMP_TL MODIFY ATTRIBUTE1 DATE

alter table XX_EMP_TL MODIFY ATTRIBUTE2 NUMBER

alter table XX_EMP_TL MODIFY ATTRIBUTE3 VARCHAR2(100)

desc XX_EMP_TL

select * from XX_EMP_TL


edit XX_EMP_TL

--====================
--ALter Table   - Drop column
--====================

ALTER TABLE XX_EMP_TL DROP COLUMN ATTRIBUTE3

select * from XX_EMP_TL

ALTER TABLE XX_EMP_TL DROP COLUMN ATTRIBUTE2

ALTER TABLE XX_EMP_TL DROP COLUMN ATTRIBUTE3



--=====================================
-- Alter View
--=====================================

CREATE OR REPLACE View XX_EMP_V
AS
select EMP_NAME, EMP_GRADE,EMP_ID, EMP_DOB from XX_EMP_TL

select * from XX_EMP_V


Comments

Popular posts from this blog

E-Text Report In Fusion | Types of E-Text reports

Supplier API's

How to pass default Parameter in cursor