Hallo,
ich habe eine frage zum PK und FK.
habe follgendes Beispiel gefunden und frage mich warum man erst unique index dann pk auf das selbe Feld macht?
CREATE TABLE meineTab (
tab_id number(38,0) NOT NULL,
name VARCHAR2(255) NOT NULL));
CREATE UNIQUE INDEX ind_tab ON meineTab (tab_id) TABLESPACE index_ts;
ALTER TABLE meineTab
ADD (CONSTRAINT pktab PRIMARY KEY (tab_id) USING INDEX TABLESPACE index_ts);
a)
Denn ist es nicht so, dass wenn man ein PK erstellt auf Feld das not null ist automatisch ein index erstellt wird, und PK sind doch grundsätzlich unique. Oder versthe ich etwas falsch?
b)
Nun zum Fremschlüssel:
bei dem sleben Beispiel was ein Statement wie folgt:
ALTER TABLE FK_Tab
ADD CONSTRAINT fk_1 FOREIGN KEY (FK_Feld) REFERENCES meineTab;
Muss man nicht auch das Feld angeben das man zuweisen möchte?wie
ALTER TABLE meine_Tab
ADD CONSTRAINT fk_1 FOREIGN KEY (FK_splate) REFERENCES meineTab (tab_id);
Gruß und Danke im Voraus