foreign-keys

Trouble defining foreign keys (MySQL)

拥有回忆 提交于 2020-01-06 10:23:54
问题 Working on an introduction to databases class assignment and running into trouble on a few foreign key. I've done a few foreign keys but every now and then I get stumped and can't figure out why it doesn't work. This example is a university database and I have section describe section; +--------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+-------------+------+-----+---------+-------+ | course_id | varchar(7) | NO | PRI |

Nested table primary and foreign key in Oracle

风格不统一 提交于 2020-01-06 08:41:53
问题 I'm trying to add a primary and foreign key to a nested table, struggling to know how. This is what I have; create or replace type profile as object ( id VARCHAR2(10), --- Suppose to be Primary Key userID VARCHAR2(10) --- Suppose to be Foreign Key for user table ); create or replace type profile_nest as table of profile; CREATE OR REPLACE TYPE user_t UNDER group_T (profile profile_nest_ty,); CREATE TABLE user OF user_t (id NOT NULL, PRIMARY KEY (id), nested table profile store as profile

LOAD DATA INFILE parent child table and foreign keys relationship

╄→гoц情女王★ 提交于 2020-01-06 07:52:08
问题 So I have 2 tables. Path table has foreign key 'media_id' connected with media table 'id'. Each media can have several paths. This all works well. The problem comes when I try to export and import these tables with csv. I can export them ok, but when I go to import them (first media table) primary key 'id' in media table is set to auto increment, and when media table is being imported with LOAD DATA INFILE it will generate new 'id' on its own, so I will loose any connection to path table.

Why I cannot assign foreign key to this column?

五迷三道 提交于 2020-01-06 06:54:45
问题 I've got a main table of users create table `users` ( `id` int (10), `first_name` varchar (192), `last_name` varchar (192), `password` varchar (96), `phone` int (10), `email` varchar (768), `date_created` timestamp ); then I have a table of accounts, with foreign key user_id referring to main table of users create table `accounts` ( `id` int (10), `user_id` int (11), `account_number` bigint (12), `account_type` varchar (192), `balance` double , `currency` varchar (9), `date_created` timestamp

Why I cannot assign foreign key to this column?

假如想象 提交于 2020-01-06 06:54:27
问题 I've got a main table of users create table `users` ( `id` int (10), `first_name` varchar (192), `last_name` varchar (192), `password` varchar (96), `phone` int (10), `email` varchar (768), `date_created` timestamp ); then I have a table of accounts, with foreign key user_id referring to main table of users create table `accounts` ( `id` int (10), `user_id` int (11), `account_number` bigint (12), `account_type` varchar (192), `balance` double , `currency` varchar (9), `date_created` timestamp

Sqlite foreign key does not work

北战南征 提交于 2020-01-06 06:41:19
问题 I read all the previous issues with the foreign keys. I did all the possible configurations but I can not enforce it to work. I can insert to the nodes table even if I don't have any record in the types table. But as I know the foreign key constraint should not allow this to happen. CREATE TABLE nodes( id int NOT NULL PRIMARY KEY , ver int NOT NULL, lock int NOT NULL, title varchar(50) NOT NULL, typeid int NOT NULL REFERENCES types(id), desc text NOT NULL, CHECK(trim(id) <> '' AND trim(ver) <

VB.Net & Access - Set two foreign keys, that refer to the same table/field

旧时模样 提交于 2020-01-06 04:56:05
问题 I have an Access database where I want to store the contacts in a company: In this database I have a table named "users" where I keep the users which will have access to the database. In the main table, named "contacts", two of my fields "insert_user" and "contact_user" refer to the user who entered the contact information and the user who actually made the contact. The way I am thinking it, I will have to set both of the fields as foreign keys to the same table/field, namely "users"/

Mysql: Change status of all child records if status of parent is updated

梦想与她 提交于 2020-01-06 03:27:05
问题 I have 2 tables 1. Parent Parent_ID(PK)| name | status -------------------------------- 1 |parent 1 |enable 2 |parent 2 |enable 3 |parent 3 |disable 2. Child Child_Id(PK)| Parent_ID(Fk of parent table) | name | status ---------------------------------------------------------- 1 |1 | child 1 | enable 2 |1 | child 2 | enable 3 |1 | child 3 | enable 4 |1 | child 4 | enable 5 |2 | child 5 | enable 6 |2 | child 6 | enable 7 |2 | child 7 | enable 8 |2 | child 8 | enable 9 |3 | child 9 | disable 10

Model - Foreign Key db_column Naming Issue

一曲冷凌霜 提交于 2020-01-05 15:17:31
问题 I am having an issue with the db_column parameter in Django. Lets say I have created a model in my models.py: class Stats(models.Model): fk = models.ForeignKey(Game, db_column='fk_gameId') score = models.IntegerField(default=0) and trying to make an insert to the table that is generated from the model, the sample code for the insert operation is like: dbQuery = Stats(fk_gameId = requestedGameId, score = gameInfo['score']) dbQuery.save() what happens is that the system throws the following

SQL: Foreign key that is a child of another foreign key

痞子三分冷 提交于 2020-01-05 11:52:53
问题 I'd like to ask regarding a particular issue I have. For example, I have a Student table that has a SchoolID and a ClassID , both of which are foreign keys to the School and Classroom tables respectively. The Class table has a SchoolID column which is a foreign key to the School table. Is there any way I can ensure that the ClassID in the Student table is a child of the SchoolID , or must I remove the SchoolID and just live with the ClassID in order to prevent any possible discrepancies? 回答1: