foreign-keys

How do I delete row with primary key using foreign key from other table?

好久不见. 提交于 2019-12-25 07:22:35
问题 I have a table called 'agenda' //translation: dairy with the following rows: idagenda // primary key title waar organisatie ... etc. ... I also have a table for the date of an diary item/event called agendadatum with the following rows: id // primary key idagenda // id from other table van //from tot // till datum // date When the field 'tot' is the date from Today it will delete the rows from the database, but the rows in the 'agenda' table remain untouched. They're not deleted, because I

Error on SELECT*FROM statement android SQLite Database

妖精的绣舞 提交于 2019-12-25 06:46:41
问题 I have a Database With a foreign key I am using the SELECT * FROM statement but I keep getting an error when I try to view the database. SELECT * FROM STATEMENT private final String MY_QUERY = "SELECT * FROM wwTable mLat INNER JOIN wwTimeTable _id ON wwTable._id=wwTimeTable.mName WHERE Table._id=wwTimetabel.mForeign"; MY KEYS public static final String KEY_ROWID = "_id"; public static final String KEY_ROWIDLL = "_id"; public static final String KEY_ROWIDTIME = "_id"; public static final

Multiple foreign keys from the same table

爷,独闯天下 提交于 2019-12-25 05:53:30
问题 i'm building a DB of a graduation projects management system. Students are divided into groups .There is groups table and faculty table. Each group has an advisor and two examiners. i'm confused here. Should i create 3 FKs from the the faculty table? 2 for examiners and 1 for advisor? here is the SQL code: create table groups ( groupID NUMBER not null, nbStudents NUMBER not null, avgGPA DOUBLE NOT NULL, projectName varchar(50) not null, advisorID NUMBER examiner1ID NUMBER examiner2ID NUMBER

MySQL foreign key relations vs mysql_insert_id to relate tables

☆樱花仙子☆ 提交于 2019-12-25 05:19:10
问题 This is for a sort of proof of concept draft to get things working, but don't want to have completely crap code. For my database, I tried to get true foreign key relations going using innoDB, but couldn't get it. Instead of using foreign keys, I decided to just pull mysql_insert_id() after inserts, saving it as a variable, then putting that variable into the related table. Is this horrible? Everything seems to work well, and I'm able to connect and relate ID's as needed. What benefits would

Django fetch all relations

时光怂恿深爱的人放手 提交于 2019-12-25 05:04:23
问题 I have an app with a similar structure as this snippet class Blog(models.Model): name = models.CharField(max_length=25) class Category(models.Model): name = models.CharField(max_length=25) blog = models.ForeignKey(Blog) class Entry(models.Model): title = models.CharField(max_length=25) category = models.ForeignKey(Category) What is the most generic way, that i will be able to use in other apps to fetch all blogs with their category and entries? I thought about creating a manager for the Blog

MySQL foreign key causing table to drop

落爺英雄遲暮 提交于 2019-12-25 04:56:07
问题 had an issue before with this code which was resolved and caused the table to work but now i am receiving error 1005 and the table cannot be created due to the fk here is the code for the first table SET FOREIGN_KEY_CHECKS = 0; DROP TABLE IF EXISTS Customer; CREATE TABLE Customer ( CustomerNumber int NOT NULL, CustomerName varchar(255), CustomerAddress varchar(255), CustomerPhoneNumber varchar(255), JoinDate varchar(255), PetName varchar(255), PayScheme varchar(255), PremiumPayDate varchar

MySQL InnoDB CASCADE?

本小妞迷上赌 提交于 2019-12-25 04:32:56
问题 I am starting to experiment with using InnoDB in web applications. I've setup some tables with a foreign key, but they are not behaving as expected. Here are my table CREATE statements: CREATE TABLE sections ( section_id INT NOT NULL AUTO_INCREMENT, title VARCHAR(30), created_at int(10) NOT NULL, updated_at int(10) NOT NULL, PRIMARY KEY(section_id) ) ENGINE=InnoDB; CREATE TABLE pages ( page_id INT NOT NULL AUTO_INCREMENT, section_idfk INT NOT NULL, PRIMARY KEY(page_id), FOREIGN KEY(section

MySQL FOREIGN KEY error, ON DELETE CASCADE

烈酒焚心 提交于 2019-12-25 04:31:32
问题 I have absolutely no clue why MySQL is having an issue with the second CREATE TABLE statement. CREATE TABLE User( uid INTEGER, url CHAR(100), firstname CHAR(40), lastname CHAR(40), PRIMARY KEY(uid) ); The below is the one that causes problems: CREATE TABLE Follows( uid INTEGER, url CHAR(100), PRIMARY KEY(uid,url), FOREIGN KEY(uid) REFERENCES User(uid), ON DELETE CASCADE, FOREIGN KEY(url) REFERENCES User(url), ON DELETE CASCADE ); Error I get is: #1064 - You have an error in your SQL syntax;

Filter objects if all its foreignkeys are in a dictionary

这一生的挚爱 提交于 2019-12-25 04:30:16
问题 what i need is to allow users to access list of Parent objects by filtering their related objects `Kid' We have a dictionary that has a 100 kid. and parents that have about 5 kids in average. if the kids in 1 parent object are all in the dictionary I want them to be listed. But not all 100 kid have to be related to the parent object. e.g if the parent have 4 kids who are in the dictionary and 1 that is not. Then do not include them. I have the code below models.py : class Parent(models.Model)

Foreign key with additional relationship constraint

随声附和 提交于 2019-12-25 03:26:09
问题 In SQL Server 2012, can I create a foreign key constraint that includes a restriction on which rows can be referenced based on other keys? Example: CREATE TABLE Client ( Id INT IDENTITY PRIMARY KEY Description NVARCHAR(200) ); CREATE TABLE Location ( Id INT IDENTITY PRIMARY KEY, Description NVARCHAR(200), ClientId INT NOT NULL, FOREIGN KEY (ClientId) REFERENCES Client(Id) ); CREATE TABLE Defect ( Id INT IDENTITY PRIMARY KEY, Description NVARCHAR(200), ClientId INT NOT NULL, LocationId INT