Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8817571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:52:49+00:00 2026-06-14T04:52:49+00:00

I am in the process of designing the databases for my system. There are

  • 0

I am in the process of designing the databases for my system. There are a lot of foreign key constraints.

I was wondering whether I could get some advice, whether I should do which of the following:

1) Specify the constraints during table creation itself ie,

CREATE TABLE IF NOT EXISTS abc
    (
    keyword VARCHAR(20) NOT NULL,
    id INT UNSIGNED NOT NULL,
    FOREIGN KEY (id) REFERENCES xyz(id) ON DELETE CASCADE ON UPDATE CASCADE
    )ENGINE=InnoDB;

2)create the table without FK constraints and ‘alter’ the table later on ie,

CREATE TABLE IF NOT EXISTS abc
    (
    keyword VARCHAR(20) NOT NULL,
    id INT UNSIGNED NOT NULL,
    )ENGINE=InnoDB;
ALTER TABLE abc ADD CONSTRAINT fk_constraint FOREIGN KEY (id) REFERENCES xyz(id)
ON DELETE CASCADE ON UPDATE CASCADE;

Table xyz is simply another table with ‘id’ as a primary key.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:52:50+00:00Added an answer on June 14, 2026 at 4:52 am

    You may create the FK at once. But this is not always possible because they can refer to each other in a circular fashion. Also, you may want to add columns later, with a FK.

    It may be slightly faster to add it at once, because MySQL has to validate and rebuild the table structure for some changes (although I’m not sure adding FKs is one of those). But this process will be reasonably fast on empty tables, so it doesn’t matter much when you add the FK.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm in the process of designing a fairly complex system. One of our primary
I am currently in the process of designing a system which will use multiple
I am in the process of designing a fairly simple login system, and I
I'm currently in the process of designing some desktop software and I've always wanted
I'm in the process of designing a system that will allow me to represent
In the process of designing an application we've come to the conclusion that the
I'm in a process of designing a multi-tier ASP.NET web application that is supposed
I'm in the process of designing my ASP.NET MVC application and I ran across
We are in the process of designing a tool to be used with HDEM(High
My team is in the process of designing a domain model which will hide

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.