referential-integrity

In MySQL, can I defer referential integrity checks until commit

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-17 07:17:25
问题 As in this question, I've been reading PoEAA and wondering if it's possible to defer referential integrity checks until commit in MySQL. I've run into this problem when wanting to insert a bunch of products and related products in the same commit. Even within a transaction, I get constraint errors when I try to insert into the related_products join table. If it helps, I'm using PHP PDO for database connections. I'd appreciate any help you could offer. 回答1: Looks like my answer is here... Like

mysql foreign key reference from a composite key

╄→尐↘猪︶ㄣ 提交于 2019-12-13 05:54:00
问题 I am creating an application that will handle and record when a student gets advised by a faculty member at a university and I need an effective way to structure the tables. My problem is coming from a lack of referential integrity, caused by the inability to create a foreign key that will reference a STUDENT on only part of a composite key in ADVISE_HIST which is (STUDENT_ID,DATE_ADVISED) here are some of the tables create table STUDENT( LNAME varchar(50), FNAME varchar(50), ID char(9)

Foreign key matching in PostgreSQL

半城伤御伤魂 提交于 2019-12-13 01:16:01
问题 Just curious, if I have this table: CREATE TABLE "post" ( "id" SERIAL, "revision" INTEGER NOT NULL DEFAULT 0, "summary" CHARACTER VARYING NOT NULL, "description" TEXT NOT NULL, "user_id" INTEGER NOT NULL REFERENCES "user" ("id") MATCH FULL ON UPDATE CASCADE ON DELETE RESTRICT, "post_type_id" INTEGER NOT NULL REFERENCES "post_type" ("id") MATCH FULL ON UPDATE CASCADE ON DELETE RESTRICT, "ctime" TIMESTAMP WITH TIME ZONE DEFAULT NOW(), PRIMARY KEY("id", "revision") ); to store posts, and this

Showing MYSQL table columns with key types and reference

蹲街弑〆低调 提交于 2019-12-12 12:45:38
问题 I need a query (INFORMATION_SCHEMA) which will for given schema and table name show me all table columns with following attributes (what key type it is: PK=>Primary Key, UQ=>Unique Key, FK=>Foreign Key, what is key name, and if it is Foreign Key what schema.table.column is referenced): COLUMN_NAME | DATA_TYPE | KEY_TYPE | KEY_NAME | REFERENCED ============+===========+==========+=============+======================== empid | int | PK | PRIMARY | empname | varchar | UQ | uq_empname | empactive

Maintaining Referential Integrity - Good or Bad?

杀马特。学长 韩版系。学妹 提交于 2019-12-12 07:07:29
问题 We are planning on introducing simple Audit Trail in our database using triggers and separate history table for each table that requires auditing. For example consider table StudentScore, it has few foreign keys (eg. StudentID, CourseID) linking it to corresponding parent tables (Student & Course). Table StudentScore ( StudentScoreID, -- PK StudentID ref Student(StudentID), -- FK to Student CourseID ref Course(CourseID), -- FK to Course ) If StudentScore requires auditing, we are planning to

Rails and referential integrity

断了今生、忘了曾经 提交于 2019-12-12 04:54:41
问题 I would like to know if it's possible to write a migration instead of of the following raw SQL statement: execute <<-SQL ALTER TABLE records ADD CONSTRAINT fk_records_domains FOREIGN KEY (domain_id) REFERENCES domains(id) ON DELETE CASCADE SQL I would like avoid using sql because i'm getting problems when trying to rollback such migration: execute <<-SQL ALTER TABLE records DROP FOREIGN KEY fk_records_categories SQL rake db:rollback == Integrity: reverting ====================================

Function to update a status flag for validity of other column?

喜欢而已 提交于 2019-12-12 02:25:42
问题 How to create a function that compares card_id with allowed_cards array elements? If it's in this array, column status must be updated to TRUE . CREATE TABLE client_1 ( id bigint NOT NULL, "time" timestamp without time zone DEFAULT now(), status boolean, card_id character varying(10), CONSTRAINT client_1_pkey PRIMARY KEY (id) ); CREATE TABLE allowed_cards ( allowed_cards character varying(10)[] ); INSERT INTO allowed_cards VALUES ('{DD3234,FF2342}'); 回答1: Enforce valid card_id at all times

Python pandas: can I add constraints like I would in a database?

一个人想着一个人 提交于 2019-12-12 00:29:26
问题 Is there any way to add constraints or foreign keys the way I would in a database? E.g. making sure a field is unique, a field is always > 0, that customer_id in the orders table always has a match in customer_id in the customer table, etc? 来源: https://stackoverflow.com/questions/32353732/python-pandas-can-i-add-constraints-like-i-would-in-a-database

A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column:

一笑奈何 提交于 2019-12-11 05:28:31
问题 First, thanks for taking the time to read this. I'm having some difficulties with trying to update a database using EF. I've used this same approach before on another project, so I'm thinking the issue is perhaps in the database, but I'm just not seeing it. The database is a legacy db in SQL 2005, and the naming convention has a lot to be desired, therefore I've been mapping the inconsistent names to something more consistent via the HasColumnName method: as in. modelBuilder.Entity<Case

Entity Framework disconnected graph and navigation property

放肆的年华 提交于 2019-12-10 19:43:51
问题 I'm working with Entity Framework 6 Code First and Fluent API. I have a one to many relationship between Visit and VisitPage (1 Visit has many VisitPage objects). This is the simplified version of the POCO classes: Visit : Id (identity), UrlReferrer, Pages. VisitPage : Id (identity), Name, Visit, VisitId First, I create a Visit object and add a VisitPage object to it. Then, I insert them into the DB. Until this point everything works OK. Observation: VisitId property in VisitPage is