3

I'm trying to make a foreign key. When I execute the query below, it returns blank with neither an explanation nor an error.

alter table MySQL."GrossHomeSales"
    add constraint fk_zip_code
        foreign key (nhs_prev_zip) references MySQL."Location" (zip_code);
5
  • Alter table is not famous for its verbose output. Are you expecting something in particular? Commented Aug 2, 2016 at 19:47
  • 1
    You can activate debugging in postgresql, maybe you see there more messages. Error Reporting and Logging Commented Aug 2, 2016 at 19:51
  • 2
    I've used this technique to create other foreign keys for other tables and it had proved to be fruition but I don't know why the one above returns nothing. And also I'm new to this community can you guide me towards how you can have sample queries or codes copied in the gray shaded area you helped edit. Commented Aug 2, 2016 at 19:56
  • 1
    What exactly is your question? Is the foreign key not created? Did you commit the alter table? Commented Aug 2, 2016 at 20:59
  • 2
    When I'm running the above query neither does it show an error nor an explanation; it just shows blank. I've used the exact same query to assign foreign keys for other tables but for some odd reason it shows blank for this one. If it'd show an error I would try to work on removing the error but since it just shows blank I have no headway. Commented Aug 2, 2016 at 21:31

1 Answer 1

1

You have not mentioned what your sql client is. If you are using psql, it does say ALTER TABLE when you make an alteration to a table. If instead you were using pgadmin 3, it would say something like

Query returned successfully with no result in 345 msec.

The reason that you are not seeing any output could be because this is really large table with several million rows, Then it could take a few minutes to create the index so don't expect instant output.

The other likely reason for not receiving any immediate response is because the table has been locked by another long running query.

Finally your question title says postgresql but your table has mysql in it's name?? (this is not related, just curious)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.