foreign-keys

How to use a foreign key in sqlite?

﹥>﹥吖頭↗ 提交于 2019-12-08 02:54:06
问题 I have two tables in sqlite, which are "connected" with an id. The app using this tables is running on Android OS. Table 1;: |id| entry 1| entry2| |1 | aaaaaa | aaaaa | |2 | bbbbbb | bbbbb | Table 2: |id| entryx| constant| |1 | aaaaa | aaaaaaaa| |1 | baaaa | baaaaaaa| |1 | caaaa | caaaaaaa| |2 | ababa | baabaaba| At the moment I delete entries with the following query, by using a loop: do{ db.delete("Table 1","id='"+cid+"'",null); db.delete("Table 2","id='"+cid+"'",null); } while(getNextID())

Connecting One table to Many tables

送分小仙女□ 提交于 2019-12-08 02:32:21
问题 I am building a commenting system where people can comment on uploaded files, messages and to-do items. What is the best way to connect the comment table table to the other various tables? Possible Solutions Solution one - use a two field foreign key. CREATE TABLE `comments`( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, foreign_key INT NOT NULL, table_name enum('files','messages','to-do'), user_id INT NOT NULL, comment TEXT NOT NULL); Solution two - Each table would have a primary key unique

Pandas create Foreign ID column based on Name column

跟風遠走 提交于 2019-12-08 02:13:56
问题 I have a simple dataframe like this for example: df = pd.DataFrame({'Name': ['John Doe', 'Jane Smith', 'John Doe', 'Jane Smith','Jack Dawson','John Doe']}) df: Name 0 John Doe 1 Jane Smith 2 John Doe 3 Jane Smith 4 Jack Dawson 5 John Doe I want to add a column ['foreign_key'] that assigns a unique ID to each unique name (but rows with the same name should have the same 'foreign_key'. So the final output looks like: df: Name Foreign_Key 0 John Doe foreignkey1 1 Jane Smith foreignkey2 2 John

How can I ask Hibernate to create an index on a foreign key (JoinColumn)?

爷,独闯天下 提交于 2019-12-08 01:57:36
问题 This is my model. class User{ @CollectionOfElements @JoinTable(name = "user_type", joinColumns = @JoinColumn(name = "user_id")) @Column(name = "type", nullable = false) private List<String> types = new ArrayList<String>(); } You can imagin there would be a table called "user_type", which has two columns, one is "user_id", the other is "type". And when I use hbm2ddl to generate the ddls, I can have this table, along with the foreign key constraint on "user_id". However, there is no index of

Get Relations of a Table

元气小坏坏 提交于 2019-12-08 01:02:09
问题 I want to get relations (or foreign keys) of a Sql Server Table in my c# code. How can i do this? Thank you 回答1: This will get all the foreign keys that dbo.YourTableName references: SELECT FK = OBJECT_NAME(pt.constraint_object_id), Referencing_col = pc.name, Referenced_col = rc.name FROM sys.foreign_key_columns AS pt INNER JOIN sys.columns AS pc ON pt.parent_object_id = pc.[object_id] AND pt.parent_column_id = pc.column_id INNER JOIN sys.columns AS rc ON pt.referenced_column_id = rc.column

Entity Framework one-to-zero-or-one foreign key association

橙三吉。 提交于 2019-12-08 00:49:35
问题 I am in the process of changing the back-end of an existing application to use Entity Framework Code First. I've used the built-in tool in Visual Studio 2015 to generate POCO classes based on my existing database. This worked perfectly for the most part, except for two classes, with a one-to-zero-or-one relationship. These are my (simplified) classes: public class Login { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public int TeamMemberId { get; set

oracle sql: not able to add foreign key to table -> invalid identifier?

大兔子大兔子 提交于 2019-12-07 23:27:30
问题 First off, I'm a real newbie to db and sql. However, I have to tables, PERSON and SPECIES and I want to add a foreign key to the table SPECIES. When trying to add the foreign key I always get the error message "ORA-900904: invalid identifier". I just can't figure out what I've done wrong and why it doesn't work?!?! This was my approach: PERSON table and primary key create table person ( name varchar2 (30), firstname varchar2 (30), persid number (8) not null ) ; alter table person add

Mysql: Programmatically remove all foreign keys

蹲街弑〆低调 提交于 2019-12-07 22:44:28
问题 I'm working with a bit of a dodgey database at the moment, there are foreign keys defined in all the wrong places all over the place, I'd like to remove them all and then start from scratch. I don't wish to remove the column, just the foreign key relationships. How can I remove all foreign keys from an entire database? (Or table by table). Thanks. Edit: Forgot to say, I have PHPMyAdmin available to use. 回答1: Here's a PHP script to loop through the information_schema.key_column_usage table and

How do I create a table with a two primary keys of two foreign keys?

邮差的信 提交于 2019-12-07 19:05:51
问题 create table Machine ( Machine_ID int primary key, Machine_Name varchar(30) Machine_Title varchar(30) ) create table Part ( Part_ID int primary key, Part_Name varchar(30), Part_Description varchar(30) ) //How do I make this table below? create table Machine-Part ( Machine_ID int foreign key references (Machine.Machine_ID), Part_ID int foreign key references (Part.Part_ID) Factory_Note varchar(30); ) Mysql complains there is a problem with syntax? Desired Result: have Table 'Machine-Part' use

How do I create a primary key using two foreign keys in Entity Framework 5 code first?

僤鯓⒐⒋嵵緔 提交于 2019-12-07 18:06:45
问题 I have an entity where the primary key consists of two foreign keys to two other tables. I have the configuration working with the following but the table is generated with two FK references. The table: domain.Entity1 MorePK (PK, FK, int, not null) Entity2_Id (PK, FK, int, not null) Entity3_Id (PK, FK, int, not null) OtherData (varchar, null) Entity2_Id1 (FK, int, null) Entity3_Id1 (FK, int, null) is generated from: public Entity1 { public int MorePK { get; set; } public int Entity2_Id { get;