Oracle Day 2
Oracle Day 2
Oracle Day 2
(
cust_id number(6),
cust_name varchar2(50),
mobile_no number(10),
dob date,
city varchar2(30),
email_id varchar2(30)
);
rollback;
commit;
update customer
set mobile_no =7878787878;
rollback;
update customer
set mobile_no =7878787878 where cust_id=100002;
commit;
-- add a column
-- drop a column
alter table customer
drop column city;
commit;
desc customer;
1. bkp a table
rollback;
desc customer;
insert into customer (select * from customer_bkp);
commit;
rollback;
commit;
desc customer;
dob date_of_birth
desc customer_data;
rollback to c;
rollback;
desc CUSTOMER_DETAILS;
999999 99999999
Modify a column
alter table customer_details
modify cust_id number(8);
bkp
truncate
modify
restore
-- Truncate a table
-- Modify
desc customer_details;
commit;
-- Delete a record
rollback;
commit;
--------------------------------------------------------------------------------
create a
insert
update
insert
alter
update
insert
alter -- commit
update
insert
insert
rollback;
--------------------------------------------------------------------------------
Constraints In Oracle:
======================
1. Primary Key
composite Key:
cust_id+mobile_no ---> Primary key(cust_id,mobile_no)
e.g First_name
3. Unique
e.g mobile_no
4. Check
-- data validation
5. Foreign Key
Violation:
--------------------------------------------------------------------------------
commit;
desc customer;
select
a.owner,a.constraint_name,a.constraint_type,b.table_name,b.column_name
from all_constraints a , all_cons_columns b where
a.constraint_name=b.constraint_name
and a.owner='HR' and a.table_name='CUSTOMER';
--------------------------------------------------------------------------------
On delete cascade
-----------------------------------------------------------------------------------
-
--Meta data tables will have all table & column level details
-----------------------------------------------------------------------------------
-
-------------------------------------------------------------------------------