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 6172531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:24:39+00:00 2026-05-23T23:24:39+00:00

I have the following 3 tables CREATE TABLE BUBBLES_CSC ( CSC_ID integer UNSIGNED NOT

  • 0

I have the following 3 tables

CREATE TABLE BUBBLES_CSC (
CSC_ID integer UNSIGNED NOT NULL AUTO_INCREMENT,
COUNTRY_NAME varchar(255) NOT NULL,
STATE_NAME varchar(255) NOT NULL,
CITY_NAME varchar(255) NOT NULL,
PRIMARY KEY(CSC_ID,STATE_NAME,CITY_NAME),
INDEX(CSC_ID ,CITY_NAME,COUNTRY_NAME )
);

CREATE TABLE BUBBLES_REGION (
REGION_ID integer UNSIGNED NOT NULL AUTO_INCREMENT,
REGION_NAME varchar(255) NOT NULL,
CSC_ID integer UNSIGNED NOT NULL,
PRIMARY KEY(REGION_ID),
FOREIGN KEY (CSC_ID) REFERENCES BUBBLES_CSC(CSC_ID) ON UPDATE CASCADE ON DELETE CASCADE,
INDEX(REGION_ID ,REGION_NAME ,CSC_ID )
);

CREATE TABLE BUBBLES_HOTEL (
HOTEL_ID integer UNSIGNED NOT NULL AUTO_INCREMENT,
NAME varchar(255) NOT NULL,
DESCRIPTION varchar(255) DEFAULT "No description",
CSC_ID integer UNSIGNED NOT NULL,
REGION_ID integer UNSIGNED NOT NULL,
STREET_ADDRESS varchar(255) DEFAULT NULL,
PRIMARY KEY(HOTEL_ID),
FOREIGN KEY (CSC_ID) REFERENCES BUBBLES_CSC(CSC_ID) ON UPDATE CASCADE,
FOREIGN KEY (REGION_ID) REFERENCES BUBBLES_REGION(REGION_ID) ON UPDATE CASCADE,
INDEX(HOTEL_ID,NAME,CSC_ID,REGION_ID)
)CHARACTER SET=utf8;

Now i know how to do a foreign key, But how to specify that the CSC_ID in BUBBLES_HOTEL should be same as the CSC_ID specified in BUBBLES_REGION for the row pointed to by REGION_ID in BUBBLES_HOTEL

  • 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-05-23T23:24:42+00:00Added an answer on May 23, 2026 at 11:24 pm

    The proper way to do this is not to have the column CSC_ID in BUBBLES_HOTEL at all. Each row in BUBBLES_HOTEL contains a link to a row in BUBBLES_REGION, which in turn contains a link to a row in BUBBLES_CSC. That’s how you identify to which row in BUBBLES_CSC a given row in BUBBLES_HOTEL corresponds. Your current design is not normalised.

    Having said that, you could achieve what you ask by replacing the two foreign keys on BUBBLES_HOTEL with just one:

    FOREIGN KEY (CSC_ID, REGION_ID) REFERENCES BUBBLES_REGION (CSC_ID, REGION_ID)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following tables CREATE TABLE `files` ( `fileid` int(11) NOT NULL AUTO_INCREMENT,
I have the following tables: CREATE TABLE `attendance_event_attendance` ( `id` int(11) NOT NULL AUTO_INCREMENT,
Say I have the following 2 tables, CREATE TABLE t1( name VARCHAR(25) NOT NULL,
I have the following table schema; CREATE TABLE `db1`.`sms_queue` ( `Id` INTEGER UNSIGNED NOT
i have following 3 tables CREATE TABLE [dbo].[dspartner]( [dspartnerid] [bigint] IDENTITY(1,1) NOT NULL, [name]
Suppose I have the following tables: CREATE TABLE Game ( GameID INT UNSIGNED NOT
I have the following mysql tables: CREATE TABLE `video` ( `video_id` int(11) unsigned NOT
I have the following table structure CREATE TABLE `table` ( `id` int(11) NOT NULL
I have the following tables: CREATE TABLE title ( booktitle VARCHAR( 60 ), title_id
I have 2 tables as the following - CREATE TABLE IF NOT EXISTS `nl_members`

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.