Impossibilité de creer 2 contraintes d'integrité sur la meme clé ??

Impossibilité de creer 2 contraintes d'integrité sur la meme clé ?? - SQL/NoSQL - Programmation

Marsh Posté le 15-12-2002 à 00:03:44    

Code :
  1. CREATE TABLE "USER" (
  2. USER_ID int not null identity (1,1),
  3. USERNAME varchar(30) not null,
  4. PASSWORD varchar(15) not null,
  5. PRIMARY KEY (USER_ID));
  6. CREATE TABLE TOPIC (
  7. TOPIC_ID int not null identity (1,1),
  8. TITLE varchar(70) not null,
  9. USER_ID int not null,
  10. PRIMARY KEY (TOPIC_ID));
  11. ALTER TABLE TOPIC
  12. ADD CONSTRAINT fk_USER_ID FOREIGN KEY (user_id) REFERENCES "USER" (USER_ID)
  13. CREATE TABLE REPONSE (
  14. NUM_REPONSE int not null identity (1,1),
  15. CONTENU text not null,
  16. USER_ID int not null,
  17. TOPIC_ID int not null,
  18. PRIMARY KEY (NUM_REPONSE));
  19. ALTER TABLE REPONSE
  20. ADD CONSTRAINT fk_USER_ID FOREIGN KEY (user_id) REFERENCES "USER" (USER_ID)
  21. ALTER TABLE REPONSE
  22. ADD CONSTRAINT fk_TOPIC_ID FOREIGN KEY (TOPIC_ID) REFERENCES "TOPIC" (TOPIC_ID)


 
j'ai executé ce script ke je viens de creer mais kan je creé ma 2eme contrainte d'integrité sur USER_ID , l'analyseur de requete me renvoie l'erreur :
 

Il existe déjà un objet nommé 'fk_USER_ID' dans la base de données.


---------------
Nothing can stop me, I'm never satisfied, I take what i want, refuse to be denied...
Reply

Marsh Posté le 15-12-2002 à 00:03:44   

Reply

Marsh Posté le 15-12-2002 à 00:18:26    

les objets doivent avoir un nom unique

Reply

Marsh Posté le 15-12-2002 à 11:38:40    

:bounce:


---------------
Nothing can stop me, I'm never satisfied, I take what i want, refuse to be denied...
Reply

Marsh Posté le 15-12-2002 à 11:45:13    

Probleme resolu
 

Code :
  1. CREATE TABLE "USER" (
  2. USER_ID int not null identity (1,1),
  3. USERNAME varchar(30) not null,
  4. PASSWORD varchar(15) not null,
  5. PRIMARY KEY (USER_ID));
  6. CREATE TABLE TOPIC (
  7. TOPIC_ID int not null identity (1,1),
  8. TITLE varchar(70) not null,
  9. USER_ID int not null,
  10. PRIMARY KEY (TOPIC_ID));
  11. ALTER TABLE TOPIC
  12. ADD CONSTRAINT fk_USER_ID FOREIGN KEY (user_id) REFERENCES "USER" (USER_ID)
  13. CREATE TABLE REPONSE (
  14. NUM_REPONSE int not null identity (1,1),
  15. CONTENU text not null,
  16. USER_ID int not null,
  17. TOPIC_ID int not null,
  18. PRIMARY KEY (NUM_REPONSE));
  19. ALTER TABLE REPONSE
  20. ADD CONSTRAINT fk_USER_ID2 FOREIGN KEY (user_id) REFERENCES "USER" (USER_ID)
  21. ALTER TABLE REPONSE
  22. ADD CONSTRAINT fk_TOPIC_ID FOREIGN KEY (TOPIC_ID) REFERENCES "TOPIC" (TOPIC_ID)


---------------
Nothing can stop me, I'm never satisfied, I take what i want, refuse to be denied...
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed