sql Enable or Disable Constraint check

21. September 2009

when bulk of loading is to be needed these type of constraint are foreign and check constraint.

 

-- Disable the constraint
ALTER TABLE 
[table name]
NOCHECK CONSTRAINT CK_aamir_hasan

-- Enable the constraint
ALTER TABLE [table name]
WITH CHECK CHECK CONSTRAINT CK_aamir_hasan

 

posted by Aamir Hasan



Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, Functions, Constraint

optimizing asp.net membership store procedure for good speed

17. September 2009

ALTER PROCEDURE [dbo].[aspnet_Profile_GetProperties]
@ApplicationName
nvarchar(256),
@UserName nvarchar(256),
@CurrentTimeUtc datetime
AS
BEGIN
-- 1. Please no more locks during reads
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

DECLARE @ApplicationId uniqueidentifier
--SELECT @ApplicationId = NULL
--SELECT @ApplicationId = ApplicationId FROM dbo.aspnet_Applications
WHERE LOWER(@ApplicationName) = LoweredApplicationName
--IF (@ApplicationId IS NULL)
-- RETURN

-- 2. No more call to Application table. We have only one app dude!
SET @ApplicationId = dbo.udfGetAppId()

DECLARE @UserId uniqueidentifier
DECLARE
@LastActivityDate datetime
SELECT
@UserId = NULL

SELECT
@UserId = UserId, @LastActivityDate = LastActivityDate
FROM dbo.aspnet_Users
WHERE ApplicationId = @ApplicationId AND LoweredUserName = LOWER(@UserName)

IF (@UserId IS NULL)
RETURN
SELECT TOP
1 PropertyNames, PropertyValuesString, PropertyValuesBinary
FROM dbo.aspnet_Profile
WHERE UserId = @UserId

IF (@@ROWCOUNT > 0)
BEGIN
-- 3. Do not update the same user within an hour
IF DateDiff(n, @LastActivityDate, @CurrentTimeUtc) > 60
BEGIN
-- 4. Use ROWLOCK to lock only a row since we know this query
-- is highly selective
UPDATE dbo.aspnet_Users WITH(ROWLOCK)
SET LastActivityDate=@CurrentTimeUtc
WHERE UserId = @UserId
END
END
END


if you are running one project then include this one also
CREATE FUNCTION dbo.udfGetAppId()
RETURNS uniqueidentifier
WITH EXECUTE AS
CALLER
AS
BEGIN
RETURN CONVERT
(uniqueidentifier, 'fd639154-299a-4a9d-b273-69dc28eb6388')
END;


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

Ajax, ALL, asp.net, Performance , SQL 2005 & 2008, TIPS



User Name: Guest

Your Ip: 38.107.191.90
Time: