0% found this document useful (0 votes)
25 views1 page

Adding Columns: Modifying Columns: Dropping Columns: Marking Columns As Unused: Renaming Columns: Marking The Table As Read-Only

The document describes SQL commands for altering table structures. It shows adding, modifying, and dropping columns from tables, as well as renaming columns and marking a table as read-only. The final command drops any columns marked as unused.

Uploaded by

cshekhar_r
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)
25 views1 page

Adding Columns: Modifying Columns: Dropping Columns: Marking Columns As Unused: Renaming Columns: Marking The Table As Read-Only

The document describes SQL commands for altering table structures. It shows adding, modifying, and dropping columns from tables, as well as renaming columns and marking a table as read-only. The final command drops any columns marked as unused.

Uploaded by

cshekhar_r
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/ 1

create table dept( 2 deptno number(2,0) constraint dept_deptno_pk primary key 3 constraint dept_deptno_ck check (deptno between 10 and

90), 4 dname varchar2(20) constraint dept_dname_nn not null); 5 create table emp( 6 empno number(4,0) constraint emp_empno_pk primary key, 7 ename varchar2(20) constraint emp_ename_nn not null, 8 mgr number (4,0) constraint emp_mgr_fk references emp (empno), 9 dob date, 10 hiredate date, 11 deptno number(2,0) constraint emp_deptno_fk references dept(deptno) 12 on delete set null, 13 email varchar2(30) constraint emp_email_uk unique, 14 constraint emp_hiredate_ck check (hiredate >= dob + 365*16), 15 constraint emp_email_ck 16 check ((instr(email,'@') > 0) and (instr(email,'.') > 0)));

Adding columns:
alter table emp add (job_id number);

Modifying columns:
alter table emp modify (comm number(4,2) default 0.05);

Dropping columns:
alter table emp drop column comm;

Marking columns as unused:


alter table emp set unused column job_id;

Renaming columns:
alter table emp rename column hiredate to recruited;

Marking the table as read-only:


alter table emp read only;

ALTER TABLE tablename DROP UNUSED COLUMNS;

You might also like