referential-integrity

How can Hard Deletes work when Foreign Keys are involved

荒凉一梦 提交于 2019-12-10 12:19:29
问题 I need some wisdom shed on the controversy over soft-deletes vs hard-deletes in a relational-database-centric application. Commentaries like this, this, and this all discourage soft-deletes as basically a hack, a dirty, easy way out, and claim that hard-deletes are the better way. I'd love to agree. But nobody seems to mention how to deal with one major, inescapable problem: how can one hard-delete a row when a foreign key constraint prevents its deletion, and when cascade-deleting is not an

Does SQLite support referential integrity?

旧时模样 提交于 2019-12-07 07:44:40
问题 I have a Django web-server configured to use SQLite. In a many-to-many relationship (with extra fields), Django forces me to use the relationship model to establish a relationship between two objects. But I'm able to create a relationship between objects, that don't yet exist in the related tables. For e.g: I have table1 and table2 which are related via table12. In table1, there is just one object called A. In table2, there is just one object called X. I can create a record in table12 that

How are consistency violations handled in event sourcing?

喜夏-厌秋 提交于 2019-12-06 06:11:05
问题 First of all, let me state that I am new to Command Query Responsibility Segregation and Event Sourcing (Message-Drive Architecture), but I'm already seeing some significant design benefits. However, there are still a few issues on which I'm unclear. Say I have a Customer class (an aggregate root) that contains a property called postalAddress (an instance of the Address class, which is a value object). I also have an Order class (another aggregate root) that contains (among OrderItem objects

How to reference groups of records in relational databases?

♀尐吖头ヾ 提交于 2019-12-05 19:27:38
Suppose we have the following table structures: Humans | HumanID | FirstName | LastName | Gender | |---------+-----------+----------+--------| | 1 | Issac | Newton | M | | 2 | Marie | Curie | F | | 3 | Tim | Duncan | M | Animals | AmimalID | Species | NickName | |----------+---------+----------| | 4 | Tiger | Ronnie | | 5 | Dog | Snoopy | | 6 | Dog | Bear | | 7 | Cat | Sleepy | I wonder how to reference a group of records in other tables. For example, I have a Foods table and an EatenBy column. Foods | FoodID | FoodName | EatenBy | |--------+----------+---------| | 8 | Rice | ??? | What I want

Does SQLite support referential integrity?

空扰寡人 提交于 2019-12-05 18:15:11
I have a Django web-server configured to use SQLite. In a many-to-many relationship (with extra fields), Django forces me to use the relationship model to establish a relationship between two objects. But I'm able to create a relationship between objects, that don't yet exist in the related tables. For e.g: I have table1 and table2 which are related via table12. In table1, there is just one object called A. In table2, there is just one object called X. I can create a record in table12 that depict a relationship between A & Y; even though Y doesn't exist in table2. My relationship model has

“polymorphism” for FOREIGN KEY constraints

左心房为你撑大大i 提交于 2019-12-05 00:27:56
There is this field in a table: room_id INT NOT NULL CONSTRAINT room_id_ref_room REFERENCES room I have three 2 tables for two kinds of rooms: standard_room and family_room How to do something like this: room_id INT NOT NULL CONSTRAINT room_id_ref_room REFERENCES standard_room or family_room I mean, room_id should reference either standard_room or family_room . Is it possible to do so? Here is the pattern I've been using. CREATE TABLE room ( room_id serial primary key, room_type VARCHAR not null, CHECK CONSTRAINT room_type in ("standard_room","family_room"), UNIQUE (room_id, room_type) );

How to enforce referential integrity on Single Table Inheritance?

一笑奈何 提交于 2019-12-04 23:57:05
I've read some of Bill Karwin's answers about single table inheritance and think this approach would be good for the setup I am considering: Playlist -------- id AUTO_INCREMENT title TeamPlaylist ------------ id REFERENCES Playlist.id teamId REFERENCES Team.id UserPlaylist ------------ id REFERENCES Playlist.id userId REFERENCES User.id PlaylistVideo ------------- id playlistId REFERENCES Playlist.id videoId REFERENCES Video.id All the CASCADE options are set to DELETE which will work correctly for when a Playlist is deleted, however, what happens if a User or Team is deleted? ie. If a User is

referential integrity in rails

≯℡__Kan透↙ 提交于 2019-12-04 14:10:42
So, I just came across the fact that rails does not support referential integrity regarding foreign keys and was fairly surprised. So, what's the best way to manage this? Is there a "rails" way for dealing with referential integrity? Ideally the app should not have to deal with all this; the db should. I was looking at plugins like foreigner. I wonder if this method has some shortcomings. How is this normally dealt with in rails? It's a design decision for Rails ActiveRecord. I consider stored procedures and constraints vile and reckless destroyers of coherence. No, Mr. Database, you can not

In MySQL, with FKs what's “CONSTRAINT” do?

删除回忆录丶 提交于 2019-12-04 06:15:18
I've looked at the MySQL 5.1 docs, and still can't figured this out -- that being I noticed a difference between the code I input into MySQL and output code by the system. What is the difference between the code sample 01 and 02, meaning 02 has added CONSTRAINT before FOREIGN KEY -- why, and what's it do? CODE_SAMPLE_01: FOREIGN KEY (TABLE_02_nID_FK__TABLE_01_sID_PK) REFERENCES TABLE_01(TABLE_01_sID_PK), CONTEXT: CREATE TABLE `TABLE_02` ( `TABLE_02_sID_PK` int(8) NOT NULL, `TABLE_02_nID_FK__TABLE_01_sID_PK` int(8) NOT NULL, `TABLE_02_cID` int(8) NOT NULL, `TABLE_02_data01` varchar(128) default

Does CouchDB supports referential integrity?

Deadly 提交于 2019-12-03 16:21:16
问题 I am new to CouchDB and learning about it. I did not come across CouchDB support for referential integrity. Can we create a foreign key for a field in the CouchDB document? For e.g. Is it possible to ensure a vendor name used in a order document is available in the vendor database? Does CouchDB support referential integrity? And Is it possible to make a field in a document as Primary key? 回答1: No, CouchDB doesn't do foreign keys as such, so you can't have it handle the referential integrity