diff --git a/SQL stuff/alterscript.sql b/SQL stuff/alterscript.sql index a94cbfd3..66a6c9d7 100644 --- a/SQL stuff/alterscript.sql +++ b/SQL stuff/alterscript.sql @@ -6,7 +6,22 @@ alter table club alter table club DISABLE constraint club_competition_fk; - + + + +alter table takes_part_in + add id number; + +where exists C + select * from takes_part_in + where club_id = match_id and club_id + +alter table takes_part_in + drop column id + + + + alter table manager ENABLE constraint manager_club_fk; diff --git a/SQL stuff/generate_lab-4.sql b/SQL stuff/generate_lab-4.sql index 8e41c7c7..8cf3b1a0 100644 --- a/SQL stuff/generate_lab-4.sql +++ b/SQL stuff/generate_lab-4.sql @@ -1,10 +1,3 @@ ---variable loops number ---loops := 10; - - - - - truncate table takes_part_in cascade;-- truncate table takes_place_in cascade;-- truncate table player cascade;-- @@ -14,7 +7,7 @@ truncate table manager cascade;-- truncate table club cascade;-- truncate table competition cascade;--competition is last since it has no foreign keys (but club holds a foreign key to competition) -declare loops number := 20; +declare loops number := 10; begin --create table countryTable (Cname varchar(20)) @@ -111,20 +104,34 @@ insert into player connect by level <=loops ; -insert into takes_part_in - select - dbms_random.value(1,loops) as club_id, - dbms_random.value(1,loops) as match_id - from dual -connect by level <=loops -; +--insert into takes_part_in +-- select club.id, match.id from club, match;--creates a table 1-1 everything into everything + +insert into takes_part_in + SELECT club_id, match_id + FROM ( + SELECT club.id as club_id, match.id as match_id + FROM club, match + ORDER BY DBMS_RANDOM.RANDOM) + WHERE rownum < 11; -insert into takes_place_in - select - dbms_random.value(1,loops) as stadium_id, - dbms_random.value(1,loops) as competition_id - from dual -connect by level <=loops -; +--insert into takes_part_in +-- select +-- dbms_random.value(1,loops) as club_id, +-- dbms_random.value(1,loops) as match_id +-- from dual +--connect by level <=loops +--; + +--insert into takes_place_in +-- select stadium.id, competition.id from stadium, competition ORDER BY DBMS_RANDOM.RANDOM limit 10; + +--insert into takes_place_in +-- select +-- dbms_random.value(1,loops) as stadium_id, +-- dbms_random.value(1,loops) as competition_id +-- from dual +--connect by level <=loops +--; end; \ No newline at end of file