Monthly Archives: July 2014

sql server – Can foreign key constraints be temporarily disabled using T-SQL?

-- Disable all table constraints
ALTER TABLE MyTable NOCHECK CONSTRAINT ALL

-- Enable all table constraints
ALTER TABLE MyTable CHECK CONSTRAINT ALL

-- Disable single constraint
ALTER TABLE MyTable NOCHECK CONSTRAINT MyConstraint

-- Enable single constraint
ALTER TABLE MyTable CHECK CONSTRAINT MyConstraint

via Stack Overflow

This was happening to me in VS 2010, despite not using R#. After digging through those links @Ryan Spears put in his post I have come across a permanent solution Source. (Note that @Maffelu’s solution did work for me, but it can switch back if I accidentally hit Left Alt + Shift).

This is also weird because Left Alt + Shift doesn’t seem to change it back, so you have to go to the source: a key binding buried in the Windows Control Panel:

Control Panel > Region and Language > Keyboards and Languages > Change Keyboards > Advanced Key Settings > Change Key Sequence > Select “Not Assigned” for both Switching Input Language and Switch Keyboard Layout.

XI9swEo

via Stack Overflow.

C# simple email and phone validation using Regular Expressions

	string emailRegex = @"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|ca|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)\b";
	string phoneRegex = @"^\d{10}$";

	Match phoneMatch = Regex.Match(phone, phoneRegex);
	Match emailMatch = Regex.Match(email, emailRegex);
	
	if (!emailMatch.Success)
	{
		yield return new ValidationResult("Email is invalid", new[] { "ContactEmail" });
	}