Mục đích: Demo việc tác hại khi không tạo index cho trường foreign key, có thể gây treo cứng hệ thốn
--0.Reset
delete cha;
commit;
delete con;
commit;
--1.Tao bang CHA
create table cha(id number);
CREATE UNIQUE INDEX BINHTV.CHA_PK ON BINHTV.CHA
(ID);
ALTER TABLE BINHTV.CHA
ADD CONSTRAINT CHA_PK
PRIMARY KEY (ID);
insert into cha values(1);
insert into cha values(2);
insert into cha values(3);
insert into cha values(4);
insert into cha values(5);
commit;
select * from cha;
--2.Tao bang CON
create table con(id number);
ALTER TABLE BINHTV.CON
ADD CONSTRAINT CON_FK
FOREIGN KEY (ID)
REFERENCES BINHTV.CHA (ID);
insert into con values(1);
insert into con values(2);
insert into con values(3);
commit;
select * from con;
--3.DEMO 1
--[Error] Execution (48: 1): ORA-02292: integrity constraint (BINHTV.CON_FK) violated - child record found
delete cha where id=3; -- Do rang buoc voi bang con, không thhể xóa cha khi vẫn còn con
--4.DEMO 2: LOCK CỨNG BẢNG
--4.1.session 1: Tạo 1 cửa sổ TOAD
delete con where id=3;
--4.2.Mo 1 session 2: Tạo 1 cửa sổ TOAD mới: Treo luon, mặc dù ko con nào có cha ID=4, do yêu cầu lock toàn bộ bảng CON, trong khi đó câu lệnh trên đang lock row id=3 ở bảng CON do đó bị treo
delete cha where id=4;
--4.3.Mo 1 session 3: Tạo 1 cửa sổ TOAD mới nữa: Treo luon, do yêu cầu lock toàn bộ bảng CON, trong khi đó câu lệnh trên đang lock row id=3 ở bảng CON do đó bị treo
delete cha where id = 5;
--4.4.Khac phuc treo bang cach:
--4.4.1 commit hoac rollback
--4.4.2. Hoặc index trường ID và chạy lại bước 4.1, 4.2, 4.3 ở trên
create index con_i1 on con(id);
--5.THÊM DỮ LIỆU LỚN
declare
begin
for i in 6..1000000 loop
insert into cha values(i);
commit;
end loop;
end;
declare
begin
for i in 3..1000000 loop
insert into con values(i);
commit;
end loop;
end;
Website không bao giờ chứa bất kỳ quảng cáo nào, mọi đóng góp để duy trì phát triển cho website (donation) xin vui lòng gửi về STK 90.2142.8888 - Ngân hàng Vietcombank Thăng Long - TRAN VAN BINH
=============================
Nếu bạn muốn tiết kiệm 3-5 NĂM trên con đường trở thành DBA chuyên nghiệp thì hãy đăng ký ngay KHOÁ HỌC ORACLE DATABASE A-Z ENTERPRISE, được Coaching trực tiếp từ tôi với toàn bộ kinh nghiệm, thủ tục, quy trình, bí kíp thực chiến mà bạn sẽ KHÔNG THỂ tìm kiếm trên Internet/Google giúp bạn dễ dàng quản trị mọi hệ thống Core tại Việt Nam và trên thế giới, đỗ OCP.
- CÁCH ĐĂNG KÝ: Gõ (.) hoặc để lại số điện thoại hoặc inbox https://m.me/tranvanbinh.vn hoặc Hotline/Zalo 090.29.12.888
- Chi tiết tham khảo:
https://bit.ly/oaz_w
=============================
2 khóa học online qua video giúp bạn nhanh chóng có những kiến thức nền tảng về Linux, Oracle, học mọi nơi, chỉ cần có Internet/4G:
- Oracle cơ bản: https://bit.ly/admin1_1200
- Linux: https://bit.ly/linux_1200
=============================
KẾT NỐI VỚI CHUYÊN GIA TRẦN VĂN BÌNH:
📧 Mail: binhoracle@gmail.com
☎️ Mobile/Zalo: 0902912888
👨 Facebook: https://www.facebook.com/BinhOracleMaster
👨 Inbox Messenger: https://m.me/101036604657441 (profile)
👨 Fanpage: https://www.facebook.com/tranvanbinh.vn
👨 Inbox Fanpage: https://m.me/tranvanbinh.vn
👨👩 Group FB: https://www.facebook.com/groups/DBAVietNam
👨 Website: https://www.tranvanbinh.vn
👨 Blogger: https://tranvanbinhmaster.blogspot.com
🎬 Youtube: https://www.youtube.com/@binhguru
👨 Tiktok: https://www.tiktok.com/@binhguru
👨 Linkin: https://www.linkedin.com/in/binhoracle
👨 Twitter: https://twitter.com/binhguru
👨 Podcast: https://www.podbean.com/pu/pbblog-eskre-5f82d6
👨 Địa chỉ: Tòa nhà Sun Square - 21 Lê Đức Thọ - Phường Mỹ Đình 1 - Quận Nam Từ Liêm - TP.Hà Nội
=============================
oracle tutorial, học oracle database, Tự học Oracle, Tài liệu Oracle 12c tiếng Việt, Hướng dẫn sử dụng Oracle Database, Oracle SQL cơ bản, Oracle SQL là gì, Khóa học Oracle Hà Nội, Học chứng chỉ Oracle ở đầu, Khóa học Oracle online,sql tutorial, khóa học pl/sql tutorial, học dba, học dba ở việt nam, khóa học dba, khóa học dba sql, tài liệu học dba oracle, Khóa học Oracle online, học oracle sql, học oracle ở đâu tphcm, học oracle bắt đầu từ đâu, học oracle ở hà nội, oracle database tutorial, oracle database 12c, oracle database là gì, oracle database 11g, oracle download, oracle database 19c, oracle dba tutorial, oracle tunning, sql tunning , oracle 12c, oracle multitenant, Container Databases (CDB), Pluggable Databases (PDB), oracle cloud, oracle security, oracle fga, audit_trail,oracle RAC, ASM, oracle dataguard, oracle goldengate, mview, oracle exadata, oracle oca, oracle ocp, oracle ocm , oracle weblogic, postgresql tutorial, mysql tutorial, mariadb tutorial, ms sql server tutorial, nosql, mongodb tutorial, oci, cloud, middleware tutorial, hoc solaris tutorial, hoc linux tutorial, hoc aix tutorial, unix tutorial, securecrt, xshell, mobaxterm, putty