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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:29:48+00:00 2026-06-09T04:29:48+00:00

I am trying to create a table that references another table in my db

  • 0

I am trying to create a table that references another table in my db however I am receiving this error.

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UInt32 PRIMARY KEY, name VARCHAR(20), handle VARCHAR(20), countryName VARCHAR(20' at line 1 

I have had a look at error #1064 on the mySQL refrence page but its abit of a vuage error just giving the outline of its structure.

 Error: 1064 SQLSTATE: 42000 (ER_PARSE_ERROR)

Message: %s near '%s' at line %d

this is the code I have tried to execute

CREATE TABLE User (userID UInt32 PRIMARY KEY, name VARCHAR(20), handle VARCHAR(20), countryName VARCHAR(20) references Countries(SID))engine=innodb;

Countries table has already been created, so I am not entirely sure what is causing the problem

any help would be greatly appreciated.

added not this is how I have defined countries

CREATE TABLE Countries (countryName VARCHAR(20) PRIMARY KEY)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-09T04:29:50+00:00Added an answer on June 9, 2026 at 4:29 am

    UPDATED response:

    Moving the constraint definition out of the table definition helped isolate the problem:

    CREATE TABLE User(
       userID UInt32 PRIMARY KEY
      ,name VARCHAR(20)
      ,handle VARCHAR(20)
      ,countryName VARCHAR(20)
    )engine=innodb;
    
    
    ALTER TABLE user ADD CONSTRAINT user_country_name_fk FOREIGN KEY(countryName) REFERENCES Countries(SID);
    

    Table creation failure was caused by the use of the UInt32 data type. Changed to int, table creation succeeded.

    Foreign key constraint was referring to the wrong column in Countries. It was referring to SID but needed to refer to countryName.

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

Sidebar

Related Questions

I have a data.frame and I'm trying to create a frequency table that shows
I am trying to create a table with values that are in a String
I am trying to figure out how to create a temporary table that is
I'm trying to translate a table RoomType. I create a Texts table that contains:
I am trying to create a template that will put items in a table.
Im trying to create an ajax (post) event that will populate a table in
I'm trying to create a <table> that doesn't exceed a certain width (let's say
I'm trying to create an SQL statement that joins two tables and returns a
I'm trying to create a table that has a primary key (Department_ID) that auto
im trying to create a sql query, that will detect (possible) duplicate customers in

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.