constraints

How to use an auto incremented primary key as a foreign key as well?

人盡茶涼 提交于 2019-12-21 04:55:13
问题 This is what I'm trying to do: I have 2 tables... CREATE TABLE `parent` ( `id` int(11) NOT NULL AUTO_INCREMENT, `data` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; CREATE TABLE `child` ( `parent_id` int(11) DEFAULT NULL, `related_ids` int(11) DEFAULT NULL, KEY `parent_id` (`parent_id`), KEY `related_ids` (`related_ids`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; And then a constraint: ALTER TABLE `parent` ADD FOREIGN KEY (`id`) REFERENCES `child` (`parent_id`);

OWL Property Restrictions vs. SHACL

六眼飞鱼酱① 提交于 2019-12-21 04:25:20
问题 Given a choice between OWL Property Restrictions and SHACL, is there any reason to choose the OWL approach any more? Particularly with respect to cardinality constraints, I'm wondering whether SHACL is considered to supercede OWL. The syntax appears similar, to my casual inspection. I am probably missing the purpose of OWL cardinality constraints. As part of an ontology, they should facilitate inferencing (a separate concern from validation). But how do cardinality constraints facilitate

Fantasy football linear programming in R with RGLPK

被刻印的时光 ゝ 提交于 2019-12-21 04:12:13
问题 long time listener first time caller to S.O... I am asking a question that has been asked very similarly before, however I don't believe I am smart enough to decipher how to implement the solution, for this I apologize. Here is the link to the question I found: Constraints in R Multiple Integer Linear Programming I am maxing over my projected fantasy points(FPTS_PREDICT_RF), subject to a 50,000 salary cap, while minimizing a 'risk' calculation that I have came up with. Now, the problem lies

Why is my Symfony2 @UniqueEntity constraint not working at all?

蹲街弑〆低调 提交于 2019-12-20 19:42:07
问题 I have the following entity class in my application: <?php namespace ...; // use ... use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;; // ... /** * @ORM\Table(name="sc_user") * @ORM\Entity(repositoryClass="...\UserRepository") * @ORM\HasLifecycleCallbacks() * @UniqueEntity(fields={"email", "username"}) */ class User implements UserInterface, \Serializable, EquatableInterface { /** * @var integer $id * * @ORM\Column(name="id", type="integer") *

Django: “Soft” ForeignField without database integrity checks

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-20 12:53:53
问题 I have a Django project that has multiple django "apps". One of them has models to represent data coming from an external source (I do not control this data). I want my other apps to be able to have references to this "external app" but I want to avoid all the fuzz of the database integrity checks. I don't want the db to have any constraints on these "soft foreign keys". Do you know how I can code a custom field that will emulate a real Django ForeignKey without creating a hard constraint on

Fix ORA-02273: this unique/primary key is referenced by some foreign keys

天涯浪子 提交于 2019-12-20 12:15:13
问题 Trying to drop a unique constraint I've got such error: ORA-02273: this unique/primary key is referenced by some foreign keys How to find the list of foreign keys by which my unique constraint is referenced? 回答1: select * from all_constraints where constraint_type='R' and r_constraint_name='YOUR_CONSTRAINT'; 来源: https://stackoverflow.com/questions/1740959/fix-ora-02273-this-unique-primary-key-is-referenced-by-some-foreign-keys

Should I check for DB constraints in code or should I catch exceptions thrown by DB

╄→尐↘猪︶ㄣ 提交于 2019-12-20 10:43:53
问题 I have an application that saves data into a table called Jobs. The Jobs table has a column called Name which has a UNIQUE constraint. The Name column is not PRIMARY KEY. I wonder if I should check for duplicate entries myself before I try to save/update a new entry or if it's better to wait for an exception thrown by the data access layer. I'm using NHibernate for this App if it's of any importance Thanks to everybody for the great input. I have found one more reason why I should validate in

Worker Scheduling Algorithm

浪子不回头ぞ 提交于 2019-12-20 10:38:03
问题 The Problem Here's the essence of the problem I want to solve. We have workers taking care of children in a nursery for set times during the weekend. There's 16 different slots to fill in one weekend. So for a 4-week month there's 64 slots to fill. We have at max 30 nursery workers (though we need much more. anybody like kids?). EDIT: Each time slot is discrete - they don't overlap. Currently there's a person who comes up with the nursery schedule each month. It's a complex and time consuming

Difference between NSLayoutAttributeLeft vs NSLayoutAttributeLeading

一个人想着一个人 提交于 2019-12-20 10:28:53
问题 What is the difference between NSLayoutAttributeLeft and NSLayoutAttributeLeading in iOS autolayouts? 回答1: "Leading" does not always mean "Left". For RTL-written languages (locales) leading edge of the object’s alignment rectangle will be located at the right side of the object. Quote from Auto Layout Guide: The attributes leading and trailing are the same as left and right for left-to-right languages such as English, but in a right-to-left environment such as Hebrew or Arabic, leading and

Limit SQL Server column to a list of possible values

孤人 提交于 2019-12-20 10:22:08
问题 How do I put a constraint on a column so that it can only contain the following values? What do you call this type of constraint? Allowed values: "yes", "no" or "maybe" Column Data Type: nvarchar(5) DBMS: SQL Server 2008 回答1: you can use a CHECK constraint ALTER TABLE <table> ADD CONSTRAINT chk_val CHECK (col in ('yes','no','maybe')) MSDN link 回答2: Yes, check a constraint is it what you need. You can declare check constraint at the table declaration: CREATE TABLE test( _id BIGINT PRIMARY KEY