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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:43:13+00:00 2026-06-02T12:43:13+00:00

I need to create 3 tables which look like this student( sid: CHAR(12) ,

  • 0

I need to create 3 tables which look like this

student(sid: CHAR(12), sname: VARCHAR(50), bdate: DATE, address: VARCHAR(50), scity: VARCHAR(20), year: CHAR(20), gpa: FLOAT)

company(cid: CHAR(8), cname: VARCHAR(20))

apply(sid: CHAR(12), cid: CHAR(8))

(Bolded attributes are primary keys)

But I’m not sure how to set the foreign keys since for instance cid of apply table is both primary key in apply table and company table ( which has the same situation for sid between apply table and student table). Thanks for any help.

These are the codes for creating tables:

myQuery = "CREATE TABLE student "
                + "(sid CHAR(12), sname VARCHAR(50), "
                + "bdate DATE, address VARCHAR(50), "
                + "scity VARCHAR(20), year CHAR(20), "
                + "gpa FLOAT) ENGINE=InnoDB;";
 myQuery = "CREATE TABLE company "
                + "(cid CHAR(8), cname VARCHAR(20), quota CHAR(8))ENGINE=InnoDB;";
myQuery = "CREATE TABLE apply "
                + "(sid CHAR(12), cid CHAR(8)) ENGINE=InnoDB;";
  • 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-02T12:43:14+00:00Added an answer on June 2, 2026 at 12:43 pm

    It looks like the apply table is a many-to-many join between student and company.

    In that case, you’d want to set student and company like you have (though posting the output of SHOW CREATE TABLE student may get you more helpful answers). So for the apply table, you want two foreign keys: one on sid which references student.sid, and one on cid which references company.cid. Maybe something like:

    ALTER TABLE apply ADD CONSTRAINT sid FOREIGN KEY (sid) REFERENCES student(sid);
    ALTER TABLE apply ADD CONSTRAINT cid FOREIGN KEY (cid) REFERENCES copmany(cid);
    

    Edit: Based on your table creation, you’re not setting the primary keys either. Add a PRIMARY KEY identifier to any column you wish to be a primary key.

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

Sidebar

Related Questions

I have two already-existing tables which look (in part) roughly like this: CREATE TABLE
I'm very new at this, but I need to create new tables from existing
I have an ASP.NET GridView which has columns that look like this: | Foo
I need to create a table in MySQL which stores the different currency symbols
I need to create pdf document which outputs all rows from mysql table, but
I need to create dozens of tables,and I need them to be innodb ,
i need run code that will create a database and populate tables. i am
I need my QT application to create a table and copy this table into
I am trying to create an application like Facebook in which each user can
Two temp tables are created and then loaded...Here's the schema. Create table #SH ([date]

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.