Tagged Questions
1
vote
1answer
25 views
Insert Row With Foreign Key Equal to ID - Circular Reference
In MySQL database I have an events table which has a circular reference to itself with the following columns.
id (PK) | user_id (FK) | event_id (FK) | title
Each new row inserted has a circular ...
0
votes
1answer
26 views
Foreign key with multiple references
I have the following three tables in mysql database named "THE_COLLEGE"
mysql> desc students;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | ...
0
votes
1answer
53 views
best relationship for this design?
There is a table users with autoincrement primary key id.
There is also a table employees (every employee is a user but not vice versa). The employees primary key is userid. The field userid is not ...
0
votes
1answer
19 views
Which of tables key to reference?
MySQL.
There is a table users with autoincrement primary key id.
There is also a table employees (every employee is a user but not vice versa). The employees primary key is userid. The field userid ...
1
vote
1answer
33 views
Getting the data from a foreign key table
I have a table that relates a user to client using both their table id's
UsersClients Table
---------------------
| userid | clientid |
---------------------
| 2 | 32 |
| 3 ...
0
votes
1answer
32 views
Is there a workaround for lack of support of cascade triggers with MySQL?
As things stand, cascaded foreign key actions do not activate triggers with MySQL. I don't want to get into the debate as to whether or not this is good, I just would like to know whether there is a ...
2
votes
2answers
126 views
MySQL - Normalization over meaningless data - Compound Primay Keys or Surrogate ID field
Please forgive my title; if you have a suggestion for it, feel free to comment.
I have a database:
DROP TABLE IF EXISTS `books`;
CREATE TABLE `books` (
`isbn` VARCHAR(255) NOT NULL,
`title` ...
0
votes
1answer
29 views
Check for records that break a foreign constraint (created with foreign_key_checks = 0)?
Is there an easy way to check for any records in a table that breaks any constraint?
The constraint was created on a populated table using "foreign_key_checks=0".
2
votes
1answer
71 views
Is it possible to check all constraints in a MySQL database?
MySQL offers the ability to temporarily disable the foreign key checks, thus allowing inconsistent data to enter the database.
Is it possible to check an entire MySQL database, table by table, row by ...
0
votes
1answer
79 views
Modify MySQL foreign key related column without dropping foreign key relation
I need to modify a foreign key related column. When I tried to alter it I got "Error on rename of 'x' to 'y' (errno: 150)" error. So I googled and found foreign key relation is the 'villain'. I ...
2
votes
1answer
396 views
Foreign key of multiple tables
I have the following 3 tables:
╔═════════════════╗
║ Companies ║
╠═════════════════╣
║ id ║
║ name ║
║ type ║
║ etc... ║
╚═════════════════╝
...
3
votes
2answers
137 views
Tablestructure for fast inserts/deletes with foreign keys
Current Situation
We have a table called c with ca. 300,000 rows. In this table we store the competitors for a specific product.
Example:
id | competitors | some infos about competitor | ...
0
votes
2answers
58 views
View for a MANY_MANY_MANY relationship
Let's say I have 3 main tables:
category, tag, url
category and tag have a MANY_MANY relationship (category_tag).
tag and url have a MANY_MANY relationship (url_tag).
I would like for a given ...
3
votes
2answers
473 views
How to make a trigger that will compare input with a value of other table?
I had made two tables with the following fields:
TABLE 1: "Bookings"
FIELD: "fk_flight_number"
FIELD: "date_of_reservation"
TABLE 2: "Flights"
FIELD: "flight_number"
FIELD: ...
2
votes
1answer
155 views
MySQL Unique Index Keylength
I am hashing keys from one table that provides a 256 bit (64 char length) alphanumeric string that I intend to use in a second table as a foreign key.
The engine of choice here is InnoDB.
There are ...
0
votes
1answer
95 views
Handling error of foreign key
How to set a FK value NULL upon receiving error for foreign key constraint?
Consider a simple table a
CREATE TABLE test
(
id int(11) NOT NULL AUTO_INCREMENT
ex_key int(11),
FOREIGN ...
0
votes
1answer
460 views
Foreign Key Constraint fails
I have the following tables:
// Base Scans
CREATE TABLE `basescans` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(100) NULL DEFAULT NULL,
`status_id` INT(10) UNSIGNED ...
1
vote
1answer
105 views
Are these custom module Drupal tables lacking foreign keys? mysqldump with table structures without data is included
I am troubleshooting a some tables in MySQL used by a custom Drupal module. Documentation for these tables is poor so I used mysqldump to get the structures in the Drupal database without the data. I ...
1
vote
3answers
155 views
Mysql error while creating FK
here is structure of both tables
category table
CREATE TABLE category (
`catID` bigint(20) NOT NULL AUTO_INCREMENT,
`title` varchar(60) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT ...
2
votes
1answer
206 views
foreign key constraints on same table
I have a table structure like this.
tblquestion
(
nQuestionId1 INT UNSIGNED PRIMARY KEY AUTO_INCREMENT NOT_NULL,
nQuestionId2 INT UNSIGNED ALLOW NULL
);
Here..nQuestionId2 has a foreign key ...
1
vote
2answers
79 views
How do automaticly delete rows from other tables
I have a MySql DB.
I have a table - recipes.
Also have 2 tables -ingredients and instructions. both have for each entry - a foreign key to the related recipe.
I want that when I delete an entry from ...
2
votes
1answer
323 views
Foreign key with multiple table options
I'm not sure if the title is very good, feel free to suggest a better one.
People can "comment" on different objects of my site,similarly to StackExchange (for example they can comment on a Question, ...
1
vote
2answers
1k views
MySQL - automatically update all references to specific table to use on delete cascade?
I have a specific table for one of my software packages on a MySQL 5.1 box which I need to drop a few hundred entries. These are user names with names in uppercase, the application is case specific ...
2
votes
1answer
360 views
MySQL 5.5.8 InnoDB Foreign Key, JOIN performance
We are using aws/rds, MySQL 5.5.8. all InnoDB.
For performance purposes, we have merged some data-elements into varchar fields; mini-sized int and date type fields; added covering indexes; ...
2
votes
2answers
232 views
Foreign key constraints with MySQL/InnoDB
I am try to do some performance testing with varchar foreign keys vs int foreign keys and was wondering how foreign key constraints effect performance of MySQL.
I assume that they effect ...
2
votes
1answer
86 views
Linking identifiers across tables in MySQL (Foreign Keys)
Given a simplified example of two tables
table Contact(ID int primary key, Name text not null)
table ContactPhone(ContactID int not null, PhoneNumber text not null)
Is there a way to tell MySQL ...
1
vote
2answers
2k views
How to use RESTRICT for Foreign Key in mysql?
In the database structure of
CREATE TABLE Country (
name varchar(40) NOT NULL,
PRIMARY KEY (name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE City (
name varchar(40) NOT NULL,
...
1
vote
1answer
219 views
Usefulness of Foreign Key WITHOUT reference option
Sorry, if this is naive question, but I searched a lot and did not get a vivid answers. Consider a simple InnoDB FOREIGN KEY without ON DELETE or ON UPDATE
I think this will avoid INSERT of a value ...
3
votes
2answers
528 views
Using Foreign Key and References for ON DELETE CASCADE in mysql
I was thinking that these two ways for creating foreign keys are the same
CREATE TABLE child1 (
id int(11) not null auto_increment,
parent_id int(11) REFERENCES parent_table(parent_id) ON DELETE ...
1
vote
2answers
441 views
Usage of RESTRICT or No ACTION in FOREIGN KEY Constraints
Sorry if this question is naive, but I was unable to understand possible usage of RESTRICT or No ACTION. Consider a simple database of
CREATE TABLE column1
(
first_id int(11) NOT NULL AUTO_INCREMENT,
...
2
votes
3answers
297 views
What is the optimal solution for converting a database schema?
I actually want to get rid of the existing constraints in the database which I know sounds crazy but we are upgrading our application to a new framework which relies on the foreign key constraint ...
2
votes
1answer
557 views
Will a row update check all child tables which have foreign key relationships in InnoDB?
I have a master table and around 60 to 70 child tables, all are InnoDB tables and have foreign key relationships with the master table.
Foreign key relations are On-Delete Cascade and On-Update ...
4
votes
2answers
689 views
Does a view need its own foreign key constraints?
Disclaimer: I'm a programmer, not a DBA, so bear with me...
I have a view that I use to just map 2 entities together. I have to do a join between a few different tables to get that:
CREATE OR ...
5
votes
1answer
2k views
MySQL, foreign key, can't create table error 150
UPDATE: Sorry, it was because i forgot to add UNSIGNED attribute to the lang_id column.
Original:
I'm trying to create a table with foreign key in MySQL.
I get this error: #1005 - Can't create table ...
1
vote
1answer
215 views
InnoDB Foreign key updating vs. manual in-application updating
I've been working on a "legacy" schema in MySQL Workbench that uses a lot of relations. All of the tables are MyISAM, however, and there are no foreign keys.
However, I'm working on a new area of the ...
0
votes
1answer
122 views
Derived value not calculating as expected using combination of FK and Triggers (MySQL)
I'm having trouble with calculating a derived value using a combination of triggers and foreign key constraints.
There are 3 tables involved in this arrangement
responses
------------------------
...
2
votes
1answer
383 views
Question on Design for User + User Groups + User Types + Subscriptions Model
I am redeveloping an existing web application with both weak source code and a weak underlying database design. I'm trying to develop things in a way that future expansion will be much easier, ...
3
votes
1answer
714 views
Foreign Key violation - not sure why
I have the following two tables with a foreign key on status_id:
mysql> describe usr_cookbook;
+-----------+-----------+------+-----+-------------------+-------+
| Field | Type | Null | ...
5
votes
3answers
227 views
What does the output of a JOIN statement look like?
I've been wanting to use joins for a while, but I'm having trouble visualizing the output so I know how to put it to use.
Let's say I have 2 tables:
CREATE TABLE Cities (
id INT UNSIGNED PRIMARY ...