foreign-keys

FOREIGN KEY ON DELETE RESTRICT Error - Oracle

♀尐吖头ヾ 提交于 2019-11-28 11:33:40
问题 Lately I have been trying to add the following foreign key in the table, with the RESTRICT Clause in Oracle with the following command.: ALTER TABLE Employee_SalHead ADD CONSTRAINT PAYROLL_SHEAD_FKEY FOREIGN KEY ( SalHead_ID ) REFERENCES SalHead ( SalHead_ID ) ON DELETE RESTRICT ENABLE; This gave me the following error: Error starting at line : 11 in command - ALTER TABLE Employee_SalHead ADD CONSTRAINT PAYROLL_SHEAD_FKEY FOREIGN KEY ( SalHead_ID ) REFERENCES SalHead ( SalHead_ID ) ON DELETE

Problem adding Foreign Key using Alter Table with existing MYSQL Database - can't add it! Help!

廉价感情. 提交于 2019-11-28 11:14:27
I have a production database where I have renamed several column's that are foreign keys. Obviously mysql makes this a real pain to do in my experience. My solution was to drop all the indexes and foreign keys, rename the id columns, and then re-add the indexes and foreign keys. This works great on mysql 5.1 on windows for the development database. I went to run my migration script on my debian server, which is also using mysql 5.1, and it gives the following error: mysql> ALTER TABLE `company_to_module` -> ADD CONSTRAINT `FK82977604FE40A062` FOREIGN KEY (`company_id`) REFERENCES `company` (

What is causing Foreign Key Mismatch error?

对着背影说爱祢 提交于 2019-11-28 11:02:11
I have an sqlite database structured as follows: CREATE TABLE IF NOT EXISTS Patient ( PatientId INTEGER PRIMARY KEY AUTOINCREMENT ); CREATE TABLE IF NOT EXISTS Event ( PatientId INTEGER REFERENCES Patient( PatientId ), DateTime TEXT, EventTypeCode TEXT, PRIMARY KEY( PatientId, DateTime, EventTypeCode ) ); CREATE TABLE IF NOT EXISTS Reading ( PatientId INTEGER REFERENCES Patient( PatientId ), DateTime TEXT REFERENCES Event (DateTime), EventTypeCode TEXT REFERENCES Event (EventTypeCode), Value REAL, PRIMARY KEY( PatientId, DateTime, EventTypeCode ) ); I insert a Patient with Id #1 then I run:

Entity Framework EntityKey / Foreign Key problem

自古美人都是妖i 提交于 2019-11-28 10:13:51
As the result of a form post, I'm trying to save a new Brand record. In my view, Gender is a dropdown, returning an Integer, which is populated from ViewData("gender") I've setup my link as follows: gID = CInt(Request.Form("Gender")) Brand.GenderReference.EntityKey = New EntityKey("DB_ENTITIES.Gender", "Id", gID) TryUpdateModel(Brand) DB.SaveChanges() Which results in the following error. Entities in 'DB_ENTITIES.Brand' participate in the 'FK_Brand_Gender' relationship. 0 related 'Gender' were found. 1 'Gender' is expected. Could someone explain the parameters in plain english to me. I've also

In what scenarios do I need foreign keys AND navigation properties in entity framework

你说的曾经没有我的故事 提交于 2019-11-28 09:58:54
My Order class has: public int CustomerId { get; set; } public Customer Customer { get; set; } Do I really need both properties to make a relation working? I am not using disconnected entities, I am using code first approach. Ying According to Julia Lerman's book: Programming Entity Framework: DbContext , the difference lies at the difficulty of updating the navigation property. In page 85, She suggests "If there is one thing you can do to make your life easier in N-Tier scenarios, it’s to expose foreign key properties for the relationships in your model." The book includes samples for both

Entity Framework on delete cascade

大兔子大兔子 提交于 2019-11-28 09:55:30
I have problem with deleting related rows in Entity Framework 4.1. I have tables with relations Book 1<--->* BookFormats I have set the on delete cascade: ALTER TABLE [dbo].[BookFormats] WITH CHECK ADD CONSTRAINT [FK_BookFormats_Book] FOREIGN KEY([BookID]) REFERENCES [dbo].[Book] ([BookID]) on delete cascade The EDMX property Then, I want to remove the all BokFormats items related to my Book object: var originalBook = m.db.Book.First(x => x.BookID == bookId); originalBook.BookFormats.Clear(); m.db.SaveChanges(); But, I get the error: The operation failed: The relationship could not be changed

Should you make a self-referencing table column a foreign key?

早过忘川 提交于 2019-11-28 09:37:40
For example to create a hierarchy of categories you use a column 'parent_id', which points to another category in the same table. Should this be a foreign key? What would the dis/advantages be? Yes. Ensures that you don't have an orphan (entry with no parent), and depending on usage, if you define a cascading delete, when a parent is deleted, all its children will also be deleted. Disadvantage would be a slight performance hit just like any other foreign key. Yes, you should. If you have an attribute in a relation of database that serves as the primary key of another relation in the same

Why use Foreign Key constraints in MySQL?

前提是你 提交于 2019-11-28 09:35:28
I was wondering, What will be my motivation to use constraint as foreign key in MySQL, as I am sure that I can rule the types that are added? Does it improve performance? Foreign keys enforce referential integrity . These constraints guarantee that a row in a table order_details with a field order_id referencing an orders table will never have an order_id value that doesn't exist in the orders table. Foreign keys aren't required to have a working relational database (in fact MySQL's default storage engine doesn't support FKs), but they are definitely essential to avoid broken relationships and

Identifying Sybase tables, fields, keys, constraints

我与影子孤独终老i 提交于 2019-11-28 09:24:21
问题 I'm trying to set up a Sybase query that will give me the following output: Table KeyType KeyNumber Column table1 PK 1 table1_id table1 FK 2 table2_id table1 FK 3 table3_id table1 FK 4 table4_id table1 Unique 5 table1_abc table1 Unique 5 table1_def In other words, I need the PK for each table, and every foreign key it has, as well as every unique key (not where a key has more than one element, such as the unique key above, this is identified by having the same KeyNumber). I'm guessing I need

Refactor foreign key to fields

泪湿孤枕 提交于 2019-11-28 09:04:28
问题 In PostgreSQL I need to refactor a table ( Purchases ); it has a foreign key to another table ( Shop ). Instead I want two fields that keep the relation in a textual way. I must NOT lose any information, the tables already contain data. Purchases.shop_id: (long) -- is the field I need to drop Purchases.shop: (characters) -- will hold the Shop's name Purchases.shop_user: (characters) -- will hold the Shop's user name. Shop.id: (long, pk) -- still referenced from Purchases Shop.name: