foreign-keys

How do I see all foreign keys to a table or column?

≯℡__Kan透↙ 提交于 2019-12-16 19:52:09
问题 In MySQL, how do I get a list of all foreign key constraints pointing to a particular table? a particular column? This is the same thing as this Oracle question, but for MySQL. 回答1: For a Table: SELECT TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = '<database>' AND REFERENCED_TABLE_NAME = '<table>'; For a Column: SELECT TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME

Mysql error 1452 - Cannot add or update a child row: a foreign key constraint fails

妖精的绣舞 提交于 2019-12-16 19:32:25
问题 I'm having a bit of a strange problem. I'm trying to add a foreign key to one table that references another, but it is failing for some reason. With my limited knowledge of MySQL, the only thing that could possibly be suspect is that there is a foreign key on a different table referencing the one I am trying to reference. I've done a SHOW CREATE TABLE query on both tables, sourcecodes_tags is the table with the foreign key, sourcecodes is the referenced table. CREATE TABLE `sourcecodes` ( `id

Entity Framework Compound Key (Many-To-Many Relationship with a Payload)

杀马特。学长 韩版系。学妹 提交于 2019-12-14 04:27:15
问题 I've got database tables like this: A person may be a member of many teams. A team may have many members. Each person may have a position (think job title) within the team. I've tried to set this up with ADO.NET Entity Framework and get errors: Error 3021: Problem in mapping fragments starting at line ... Each of the following columns in table Membership is mapped to multiple conceptual side properties: Membership.PersonId is mapped to <MembershipPerson.Membership.PersonId, MembershipPerson

Adding new fields vs creating separate table

和自甴很熟 提交于 2019-12-14 03:45:03
问题 I am working on a project where there are several types of users (students and teachers). Currently to store the user's information, two tables are used. The users table stores the information that all users have in common. The teachers table stores information that only teachers have with a foreign key relating it to the users table. users table id name email 34 other fields teachers table id user_id subject 17 other fields In the rest of the database, there are no references to teachers.id

Retrieving column from a SQLalchemy relationship

跟風遠走 提交于 2019-12-14 03:21:28
问题 I'm working on some wxpython widgets that integrate SQLalchemy, CRUD stuff. I've got a wx.ComboBox that lists the rows of a table linked by a relationship. class User(Base): __tablename__ = 'user' id = Column(Integer, primary_key=True) name = Column(String(250), nullable=False) class Category(Base): __tablename__ = 'category' id = Column(Integer, primary_key=True) name = Column(String(250), nullable=False) class Thing(Base): __tablename__ = 'thing' id = Column(Integer, primary_key=True)

MySQL foreign key having multiple (conditional) possible values

我的未来我决定 提交于 2019-12-14 03:18:58
问题 My idea is to use two entries (one containing the referenced table name and one containing the key in that table) in one table to reference one of several other tables. The relevant parts of the table: CREATE TABLE people ( peopleid SMALLINT UNSIGNED auto_increment, name VARCHAR(40) NOT NULL, prevname VARCHAR(40), role ENUM('Teacher', 'Mentor', 'Administrator'), roleid SMALLINT UNSIGNED ) Note:Teacher and Mentor are tables. If the person is an administrator, RoleID would be null. I want the

how to create foreign reference key for composition primary key

你离开我真会死。 提交于 2019-12-14 02:33:07
问题 Suppose we have the following two tables Create table Bank ( Bank_ID Numeric Not Null, Bank_Card Numeric Not Null, Primary Key(Bank_ID, Bank_Card) ) Create table Customer ( Customer_ID Numeric Not Null, Name varchar(30) Not Null, Primary key(Customer_ID) ) Where Customer_ID is generated by concatenating Bank_ID and Bank_Card. How can I set foreign key Customer_ID to reference Bank_ID and Bank_Card 回答1: What you want is a constraint, but it's not a FK (foreign key) constraint.(A FK constraint

Referencing the foreign key of another schema

岁酱吖の 提交于 2019-12-14 02:16:44
问题 For my project I am using oracle database where I have to work with 2 different database schema. Consider the following scenario please - I have a schema A and in it I have a table table_a with a primary key apk And I have another schema B and in it I have a table table_b with a primary key bpk If both of these tables are in a same database then I can easily make a primary key - foreign key relationship. But can I make a primary key - foreign key relation ship (or something like this) between

Can't insert foreign key value into linking table

前提是你 提交于 2019-12-14 00:58:52
问题 I am currently trying to insert data into a table called "customer_quote" , this table acts as a linking table between the "customer" table and the "customer_tariffs" table. It also records the user who sumbitted the data via the "user" table. Here is a schema of my db: http://i.imgur.com/LOG1T.png and here is a screenshot of the table that is not allowing me to insert into it. http://i.imgur.com/i2wiU.png This is the process in how I insert into my db: Insert data into customer table

Find minimum datetime while using FK in two different tables

大城市里の小女人 提交于 2019-12-13 23:57:20
问题 I have 2 tables: COURSE ------ Id Name TEST ------ Id CourseId (FK to `COURSE.ID`) DATETIME NUMBERS Suppose COURSE table with ID 1,2 (only 2 columns) and TEST table with 8 numbers of data having different DATETIME and CourseId of 1 (3 columns) and 2 (6 columns). I want to find the minimum DATETIME,CourseID and Name by joining these 2 tables. The below query is giving a 2 output: (SELECT min([DATETIME]) as DATETIME ,[TEST].CourseID,Name FROM [dbo].[TEST] left JOIN [dbo].[COURSE] ON [dbo].[TEST