MySQL terminology “constraints” vs “foreign keys” difference?

Yes, a foreign key is a type of constraint. MySQL has uneven support for constraints: PRIMARY KEY: yes as table constraint and column constraint. FOREIGN KEY: yes as table constraint, but only with InnoDB and BDB storage engines; otherwise parsed but ignored. CHECK: parsed but ignored in all storage engines. UNIQUE: yes as table constraint … Read more

Adding named foreign key constraints in a SQL Create statement

In SQL Server, you can use the constraint keyword to define foreign keys inline and name them at the same time. Here’s the updated script: CREATE TABLE galleries_gallery ( id INT NOT NULL PRIMARY KEY IDENTITY, title NVARCHAR(50) UNIQUE NOT NULL, description VARCHAR(256), templateID INT NOT NULL CONSTRAINT FK_galerry_template REFERENCES galleries_templates(id), jsAltImgID INT NOT NULL … Read more

Why can’t I use a type argument in a type parameter with multiple bounds?

I’m also not sure why the restriction is there. You could try sending a friendly e-mail to the designers of Java 5 Generics (chiefly Gilad Bracha and Neal Gafter). My guess is that they wanted to support only an absolute minimum of intersection types (which is what multiple bounds essentially are), to make the language … Read more

C# Generic constraints to include value types AND strings

Maybe you could restrict to IConvertible types? All the system primitives that can be converted using these interface methods also implement the interface, so this restriction would require T to be one of the following: Boolean Byte Char DateTime Decimal Double Int (16, 32 and 64-bit) SByte Single (float) String UInt (16, 32 and 64-bit) … Read more

SQL constraint minvalue / maxvalue?

SQL Server syntax for the check constraint: create table numbers ( number int not null check(number >= 1234 and number <= 4523), … ) create table numbers ( number int not null, check(number >= 1234 and number <= 4523), … ) create table numbers ( number int not null, constraint number_range_check check(number >= 1234 and … Read more

Temporarily disable all foreign key constraints

To disable foreign key constraints: DECLARE @sql nvarchar(max) = N”; ;WITH x AS ( SELECT DISTINCT obj = QUOTENAME(OBJECT_SCHEMA_NAME(parent_object_id)) + ‘.’ + QUOTENAME(OBJECT_NAME(parent_object_id)) FROM sys.foreign_keys ) SELECT @sql += N’ALTER TABLE ‘ + obj + N’ NOCHECK CONSTRAINT ALL; ‘ FROM x; EXEC sys.sp_executesql @sql; To re-enable: DECLARE @sql nvarchar(max) = N”; ;WITH x AS … Read more