constraints

What is the purpose of constraint naming

…衆ロ難τιáo~ 提交于 2019-11-26 22:06:43
What is the purpose of naming your constraints (unique, primary key, foreign key)? Say I have a table which is using natural keys as a primary key: CREATE TABLE Order ( LoginName VARCHAR(50) NOT NULL, ProductName VARCHAR(50) NOT NULL, NumberOrdered INT NOT NULL, OrderDateTime DATETIME NOT NULL, PRIMARY KEY(LoginName, OrderDateTime) ); What benefits (if any) does naming my PK bring? Eg. Replace: PRIMARY KEY(LoginName, OrderDateTime) With: CONSTRAINT Order_PK PRIMARY KEY(LoginName, OrderDateTime) Sorry if my data model is not the best, I'm new to this! Here's some pretty basic reasons. (1) If a

How to add “on delete cascade” constraints?

柔情痞子 提交于 2019-11-26 21:40:21
In PostgreSQL 8 is it possible to add ON DELETE CASCADES to the both foreign keys in the following table without dropping the latter? # \d scores Table "public.scores" Column | Type | Modifiers ---------+-----------------------+----------- id | character varying(32) | gid | integer | money | integer | not null quit | boolean | last_ip | inet | Foreign-key constraints: "scores_gid_fkey" FOREIGN KEY (gid) REFERENCES games(gid) "scores_id_fkey" FOREIGN KEY (id) REFERENCES users(id) Both referenced tables are below - here: # \d games Table "public.games" Column | Type | Modifiers ----------+------

How can I use interface as a C# generic type constraint?

北城余情 提交于 2019-11-26 21:40:20
Is there a way to get the following function declaration? public bool Foo<T>() where T : interface; ie. where T is an interface type (similar to where T : class , and struct ). Currently I've settled for: public bool Foo<T>() where T : IBase; Where IBase is defined as an empty interface that is inherited by all my custom interfaces... Not ideal, but it should work... Why can't you define that a generic type must be an interface? For what it's worth, I want this because Foo is doing reflection where it needs an interface type... I could pass it in as a normal parameter and do the necessary

MySQL Removing Some Foreign keys

一曲冷凌霜 提交于 2019-11-26 21:24:26
I have a table whose primary key is used in several other tables and has several foreign keys to other tables. CREATE TABLE location ( locationID INT NOT NULL AUTO_INCREMENT PRIMARY KEY ... ) ENGINE = InnoDB; CREATE TABLE assignment ( assignmentID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, locationID INT NOT NULL, FOREIGN KEY locationIDX (locationID) REFERENCES location (locationID) ... ) ENGINE = InnoDB; CREATE TABLE assignmentStuff ( ... assignmentID INT NOT NULL, FOREIGN KEY assignmentIDX (assignmentID) REFERENCES assignment (assignmentID) ) ENGINE = InnoDB; The problem is that when I'm

UIScrollView and Constraints

Deadly 提交于 2019-11-26 20:57:10
I'm trying to place a UIImageView at the top of a UIScrollView and when I constrain the UIScrollView to the sides of the View Controller and constrain the UIImageView to the top and make the width of the UIImageView equal to the UIScrollView it makes the UIImageView way wider than the UIScrollView, and much taller than expected. Any idea what I'm doing wrong? Storyboard: Preview: Check that following constraints are added to your view: Go to Storyboard -> Select your view Now at right-bottom corner you can see small buttons to add constraints Select "Pin" button And mark all 4 constraints for

Is there a C# generic constraint for “real number” types? [duplicate]

旧巷老猫 提交于 2019-11-26 20:43:06
Possible Duplicate: C# generic constraint for only integers Greets! I'm attempting to set up a Cartesian coordinate system in C#, but I don't want to restrict myself to any one numerical type for my coordinate values. Sometimes they could be integers, and other times they could be rational numbers, depending on context. This screams "generic class" to me, but I'm stumped as to how to constrict the type to both integrals and floating points. I can't seem to find a class that covers any concept of real numbers... public class Point<T> where T : [SomeClassThatIncludesBothIntsandFloats?] { T myX,

SQL Script to find Foreign keys to a specific table?

穿精又带淫゛_ 提交于 2019-11-26 20:35:52
问题 Is there a query that will get me foreign keys directed at a specific table column? For example, say I had these three tables: __________ |Table A | ---------- |Id | ---------- ___________ |Table B | ----------- |Id | |TableAId | (Foreign Key to TableA.Id) ----------- ___________ |Table C | ----------- |Id | |TableAId | (Foreign Key to TableA.Id) ----------- I need a query along the lines of "Select * Foreign Keys directed at TableA.Id" that returned "Table C: TableAId", "Table B: TableAId".

Why use generic constraints in C#

限于喜欢 提交于 2019-11-26 19:50:54
问题 I've read an excellent article on MSDN regarding Generics in C#. The question that popped in my head was - why should i be using generic constraints? For example, if I use code like this: public class MyClass<T> where T : ISomething { } can't I switch ALL references of T in this class with ISomething ? What's the benefit of using this approach? 回答1: You ask, "can't I switch ALL references of T in this class with ISomething ?" So I think you mean to compare: public class MyClass<T> where T :

Postgresql: Conditionally unique constraint

懵懂的女人 提交于 2019-11-26 19:00:45
问题 I'd like to add a constraint which enforces uniqueness on a column only in a portion of a table. ALTER TABLE stop ADD CONSTRAINT myc UNIQUE (col_a) WHERE (col_b is null); The WHERE part above is wishful thinking. Any way of doing this? Or should I go back to the relational drawing board? 回答1: PostgreSQL doesn't define a partial (i.e. conditional) UNIQUE constraint - however, you can create a partial unique index . PostgreSQL uses unique indexes to implement unique constraints, so the effect

How to remove constraints from my MySQL table?

本秂侑毒 提交于 2019-11-26 18:49:30
问题 I want to remove constraints from my table. My query is: ALTER TABLE `tbl_magazine_issue` DROP CONSTRAINT `FK_tbl_magazine_issue_mst_users` But I got an error: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'constraint FK_tbl_magazine_issue_mst_users ' at line 1 回答1: Mysql has a special syntax for dropping foreign key constraints: ALTER TABLE tbl_magazine_issue DROP FOREIGN KEY FK_tbl_magazine_issue