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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:25:07+00:00 2026-06-12T15:25:07+00:00

my question is: How should I edit the following tables: CREATE TABLE users( id

  • 0

my question is: How should I edit the following tables:

CREATE TABLE users(
id int UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name varchar(20) NOT NULL,
surname varchar(20) NOT NULL,
faculty varchar(35) NOT NULL,
username varchar(20) NOT NULL UNIQUE,
password varchar(20) NOT NULL,
is_admin boolean NOT NULL DEFAULT 0,
account_limit int UNSIGNED,
created_at datetime
) CHARACTER SET utf8 COLLATE utf8_general_ci;



CREATE TABLE test_results(
id int UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
test_id int UNSIGNED NOT NULL,
test_person_id int UNSIGNED NOT NULL,
score float UNSIGNED NOT NULL,
standard_deviation float UNSIGNED NOT NULL,
average_answer_time float UNSIGNED NOT NULL, 
removed boolean NOT NULL DEFAULT 0,
created_at datetime,
FOREIGN KEY (test_id) REFERENCES test_tasks(id) ON UPDATE CASCADE, FOREIGN KEY (test_person_id) REFERENCES test_persons(id) ON UPDATE CASCADE) CHARACTER SET utf8 COLLATE utf8_general_ci;

So that if I delete a row from the users-table, I don’t get any constraint errors etc. in the test_results-table if a row in test_results has a row which has a foreing key that references to the user-table row?

UPDATE: sorry I hesitated when making the question:

here are all my tables:

CREATE TABLE users(
id int UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name varchar(20) NOT NULL,
surname varchar(20) NOT NULL,
faculty varchar(35) NOT NULL,
username varchar(20) NOT NULL UNIQUE,
password varchar(20) NOT NULL,
is_admin boolean NOT NULL DEFAULT 0,
account_limit int UNSIGNED,
created_at datetime
) CHARACTER SET utf8 COLLATE utf8_general_ci;


CREATE TABLE test_groups(
id int UNSIGNED AUTO_INCREMENT PRIMARY KEY,
user_id int UNSIGNED NOT NULL,
name varchar(60) NOT NULL, 
password varchar(20) NOT NULL,
tests varchar(60),
created_at datetime,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE
) CHARACTER SET utf8 COLLATE utf8_general_ci;



CREATE TABLE test_persons(
id int UNSIGNED AUTO_INCREMENT PRIMARY KEY,
group_id int UNSIGNED NOT NULL,
username varchar(45) NOT NULL UNIQUE,
tries int UNSIGNED NOT NULL,
created_at datetime,
FOREIGN KEY (group_id) REFERENCES test_groups(id) ON DELETE CASCADE ON UPDATE CASCADE
) CHARACTER SET utf8 COLLATE utf8_general_ci;



CREATE TABLE test_tasks(
id int UNSIGNED AUTO_INCREMENT PRIMARY KEY,
user_id int UNSIGNED NOT NULL,
name varchar(45) NOT NULL,
type varchar(20) NOT NULL,
description text NOT NULL,
question_time int UNSIGNED DEFAULT 500,
answer_time int UNSIGNED DEFAULT 3000,
random_questions boolean NOT NULL DEFAULT 1,
questions varchar(150),
created_at datetime,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE) CHARACTER SET utf8 COLLATE utf8_general_ci;



CREATE TABLE test_results(
id int UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
test_id int UNSIGNED NOT NULL,
test_person_id int UNSIGNED NOT NULL,
score float UNSIGNED NOT NULL,
standard_deviation float UNSIGNED NOT NULL,
average_answer_time float UNSIGNED NOT NULL, 
removed boolean NOT NULL DEFAULT 0,
created_at datetime,
FOREIGN KEY (test_id) REFERENCES test_tasks(id) ON UPDATE CASCADE, FOREIGN KEY (test_person_id) REFERENCES test_persons(id) ON UPDATE CASCADE) CHARACTER SET utf8 COLLATE utf8_general_ci;

NOW IF I TRY TO REMOVE A ROW FROM user-table I get constraint error, why? I’m new with mysql

  • 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-12T15:25:08+00:00Added an answer on June 12, 2026 at 3:25 pm

    write

    ALTER TABLE `test_results`
    ADD CONSTRAINT `tbl_userplan_ibfk_1` 
    FOREIGN KEY (`test_person_id`) REFERENCES `test_persons(id)`  
    ON DELETE CASCADE ON UPDATE CASCADE
    

    and foreign key worked in the way @David W described in comment

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

Sidebar

Related Questions

I'm currently developing and I came up to the following question: How can/should I
This should be a pretty straightforward question. I have the following code, which forms
Table has surrogate primary key generated from sequence. Unfortunately, this sequence is used for
I have three tables objects , (primary key object_ID ) flags (primary key flag_ID
I'm building a webapp that allows users to create, edit, and save documents. The
I have created an sqlite table using the following statement: CREATE TABLE IF NOT
Given the following table (much simplified for the purposes of this question): id perPeriod
This is a MySQL question: I have a table with the following structure. reference
Question should say it all. Let's say there's a local file mydefaultvalues.txt, separated from
Question Should one discard a packet with an unknown IPv6 extension header? Details I

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.