foreign-keys

Drop all foreign keys in a table

ぃ、小莉子 提交于 2020-01-02 09:58:48
问题 I had this script which worked in sql server 2005 -- t-sql scriptlet to drop all constraints on a table DECLARE @database nvarchar(50) DECLARE @table nvarchar(50) set @database = 'dotnetnuke' set @table = 'tabs' DECLARE @sql nvarchar(255) WHILE EXISTS(select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where constraint_catalog = @database and table_name = @table) BEGIN select @sql = 'ALTER TABLE ' + @table + ' DROP CONSTRAINT ' + CONSTRAINT_NAME from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where

Why does EF Code First [InverseProperty] attribute fail to work when used with [ForeignKey] attribute?

自作多情 提交于 2020-01-02 07:13:26
问题 Using: EF 4.3.1, Visual Studio 2010, SQL CE 4.0 My understanding is that when declaring Foreign Keys with DataAnnotation in EF, it can be done either of the following ways: Option 1- [ForeignKey("Player1Home")] public long? HPlayer1Id { get; set; } public virtual Player Player1Home { get; set; } Option 2- public long? HPlayer1Id { get; set; } [ForeignKey("HPlayer1Id")] public virtual Player Player1Home { get; set; } Problem: When the InverseProperty DataAnnotation gets used with Option 2 an

Query is resulting in 1 row with null values when id is not found

旧时模样 提交于 2020-01-02 05:29:08
问题 The exact query: SELECT coupon_coupons . code , coupon_coupons . discountType AS 'type', coupon_coupons . discountAmount AS 'amount', coupon_coupons . discountApplied AS 'applied', coupon_coupons . description , group_concat( coupon_targetsku . sku separator ';') AS 'targetsku' FROM coupon_coupons LEFT JOIN coupon_targetsku ON coupon_coupons . code = coupon_targetsku . code WHERE coupon_coupons . code = 'testCode' coupon_coupons.code = primary key coupon_targetsku.code = fk(coupon_coupons

Is there something like `ForeignKey` in Google App Engine's `webapp`?

大城市里の小女人 提交于 2020-01-02 04:00:09
问题 I'm using Google App Engine with their webapp framework. Is there something like Django's ForeigKey in webapp ? i.e. I have a model and I want it to have a property/field that points at another model. Possible? 回答1: There is a db.ReferenceProperty. You need to be aware of two things when using it: automatic dereferencing (which is another datastore RPC call) and the entity being referenced is not required to exist (so you will need to manually check it). When using db.ReferenceProperty make

SQLite Foreign Key Constraint Failed (code 787)

寵の児 提交于 2020-01-02 00:52:35
问题 I ran into the Foreign Key Constraint Failed (code 787) error when I tried to upgrade my database. The only change I did was try to add a 4th entry to my InsertStatus . I looked around and I read that using ON DELETE CASCADE should solve my problem so I tried placing it at all my FK references and tried again but still the same problem. Logcat points to my onUpgrade and all the DROP TABLES in it ( i tried removing it one at a time to see which ones were bad and apparently all of them were ).

How to find all foreign keys?

痴心易碎 提交于 2020-01-01 16:48:30
问题 I'd like to find all referencing tables in my db that have a foreign key that points to a specific referenced table. Is there a query that I can run to do this? Not sure if the question is confusing. Let me know if it is and I can try to explain it in more detail. 回答1: The following query or Modification tehreof will do - in Sql server You can also supply catalog and schema info select tab1.TABLE_NAME from INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS as ref inner join INFORMATION_SCHEMA.TABLE

Create Foreign Key using Data Annotations

馋奶兔 提交于 2020-01-01 05:18:12
问题 In the code below, I need to set a foreign key constrant on ParentInfoAddProperties.ParentQuestionAnswersId so that it is dependent on ParentQuestionAnswers.Id (which is a Primary Key). I am attempting to do so using data annotations but Entity Framework 6 wants to create a new Foreign Key column in my ParentQuestionAnswers table which references the ParentInfoAddProperties.Id column not the ParentInfoAddProperties.ParentQuestionAnswersId column. I do not want Entity Framework to create a new

Rails - how do I validate existence of a row referenced by foreign key

◇◆丶佛笑我妖孽 提交于 2020-01-01 04:12:20
问题 Given that the "Rails Way" seems to be not to use foreign key constraints, I'm looking for an alternative that will allow me to validate that the row a foreign key references does in fact exist in TableA before I save an object in TableB with table_a_id. The only resource I've found to do this so far (can't find a link to the blog post it was mentioned in, was dated 2007) doesn't appear to be compatible with Rails 3.2, so can anyone suggest a way of doing this? I'm currently looking at

Foreign Key add fails in MySQL with Error Code 1005, number 150

霸气de小男生 提交于 2020-01-01 02:35:07
问题 So I'm attempting to add a new foreign key to one of my tables as such: ALTER TABLE `UserTransactions`.`ExpenseBackTransactions` ADD CONSTRAINT `FK_EBTx_CustomAccountID` FOREIGN KEY (`CustomAccountID` ) REFERENCES `UserTransactions`.`CustomAccounts` (`CustomAccountID`) ON DELETE NO ACTION ON UPDATE NO ACTION, ADD INDEX `FK_EBTx_CustomAccountID` (`CustomAccountID` ASC) ; and I keep getting the following error: Error Code: 1005 Can't create table './UserTransactions/#sql-187a_29.frm' (errno:

Is string or int preferred for foreign keys?

泄露秘密 提交于 2019-12-31 21:42:13
问题 I have a user table with userid and username columns, and both are unique. Between userid and username , which would be better to use as a foreign key and why? My Boss wants to use string, is that ok? 回答1: It looks like you have both a surrogate key ( int userId ) and a natural key ( char or varchar username ). Either column can be used as a Primary key for the table, and either way, you will still be able to enforce uniqueness of the other key. There are many existing discussions on the