foreign-keys

Inserting and querying data from table with foreign key in SQLite

被刻印的时光 ゝ 提交于 2019-12-11 19:27:58
问题 I wanted to create two related tables. My query that is creating tables looks like this: static final String SQL_CREATE_TABLE_LISTS = "CREATE TABLE Lists(Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT);"; static final String SQL_CREATE_TABLE_ITEMS = "CREATE TABLE Items(IdList INTEGER, ItemName TEXT, FOREIGN KEY(IdList) REFERENCES Lists(Id));"; I want now insert and select some data from table Items, but I do not know how the query should looks like. Lets say I have one record in table Lists:

NHibernate: populate list with uncommitted data related only by FK in database

本小妞迷上赌 提交于 2019-12-11 19:26:14
问题 This is an elaboration and clarification of this question. Suppose I have two tables, Foo and Bar . Bar has a FK to Foo . In the application, the tables are represented by classes and Foo has a list of Bar s. Bar has a property for the id of the Foo it has a FK to in the database. In the context of a Session and Transaction with IsolationLevel.ReadUncommitted , I add an instance of Foo to the database, assign the generated id to the Foo_id property of an instance of Bar and also add it to the

One field with two references in MySQL

那年仲夏 提交于 2019-12-11 18:37:24
问题 I have three tables: CREATE TABLE Address ( ResidentID CHAR(5) NOT NULL, Location varchar(255) NOT NULL, KEY ResidentID(ResidentID) ); CREATE TABLE Customer ( CustomerID CHAR(5) NOT NULL, ContactName varchar(40) NOT NULL, PRIMARY KEY (CustomerID) ); CREATE TABLE Supplier ( SupplierID CHAR(5) NOT NULL, SupplierName varchar(40) NOT NULL, PRIMARY KEY (SupplierID) ); I want to store CustomerID and SupplierID in the Address.ResidentID field with using of foreign keys: ALTER TABLE Address ADD

how to save related models with non-null foreign key

为君一笑 提交于 2019-12-11 17:36:26
问题 I have two models: User has_one :email Email belongs_to :user I put the email_id foreign key (NOT NULL) inside users table. Now I'm trying to save it in the following way: @email = Email.new(params[:email]) @email.user = User.new(params[:user]) @email.save This raises a db exception, because the foreign key constraint is not met (NULL is inserted into email_id). How can I elegantly solve this or is my data modeling wrong? 回答1: This should work as expected. @email = Email.create(params[:email]

I need to run 2 twaitforfile in the same subjob talend

笑着哭i 提交于 2019-12-11 17:30:11
问题 I need to run 2 file watchers in the same subjob using talend. Right now If I link them together I get only one file watching running when I run talend. Below is what I have. Is there a way to execute them together. The reason for this is because im trying to get the Fk from one table into the tmap from another table, so any other suggestion on how to do this is also appreciated: enter image description here 回答1: In one subjob, you can only have one 'beginning' component (the one with the

Foreign key constraint is incorrectly formed with Composite Keys

烂漫一生 提交于 2019-12-11 17:22:48
问题 I have a table "theaters". In which (theater_name,area_name,station) are composite key.And in the table "cubelists" I have columns (thtr_name,area,stn) which are to be referred to (theater_name,area_name,station) of table "theaters". The problem here is the combination of the columns - (theater_name,area_name,station) in table "theaters" is unique as it is a composite key. But each column separately is not unique. Then how can I refer these columns from table "cubelists"? Schema::create(

Can SQL/Access display foreign key rows as columns?

左心房为你撑大大i 提交于 2019-12-11 17:20:02
问题 I have an MS Access table that has a many-to-one key to another one, and I would like a query to display those items in one row. For example, Foo, Bar and Baz link to the row with ID 1, so I would like to display: 1 | Foo | Bar | Baz instead of 1 | Foo 1 | Bar 1 | Baz 回答1: Look at Access's PIVOT TRANSFORM. I think that is what you will need. 来源: https://stackoverflow.com/questions/965981/can-sql-access-display-foreign-key-rows-as-columns

How to create one table which shares common id with another and which row gets removed in both tables once it's removed from first

爷,独闯天下 提交于 2019-12-11 16:49:14
问题 How to create one table which shares common id with another and which row gets removed in both tables once it's removed from first? I heard about FOREIGN KEY, REFERENCES but not sure how to actually create such tables. Any example to get me started? 回答1: I think you're either talking about a cascading delete or something really weird that you shouldn't do. :) Info on foreign keys: http://www.postgresql.org/docs/8.3/static/tutorial-fk.html Info on cascading deletes (search the page for "ON

Update failing on Self Referential Foreign key with Room update method

会有一股神秘感。 提交于 2019-12-11 15:59:12
问题 I need to create folder structure using Room . I had followed this approach. @Entity(foreignKeys = @ForeignKey(entity = NodeEntity.class, parentColumns = "id", childColumns = "parentId", onDelete = CASCADE), indices = {@Index(value = {"parentId"})}) public class NodeEntity { @PrimaryKey @NonNull private String id; private int isLeafItem; private int level; private String name; private String parentId; private double price; private int quantity; private String tags; @TypeConverters

best way to keep track of myql changes

本秂侑毒 提交于 2019-12-11 15:35:28
问题 I'm using MySQL workbench's EER tool to make the database design for an application I'm developing. it is very important to track data changes on the DB, so i was following this post which makes a lot of sense the accepted answer. the problem im having is that i am not good understanding the primary keys so im a little confused on how this should work, since every time a change is made there will be another row inserted with the same Id, therefore the DB wouldn't allow it am I right? And i