Saturday, August 30, 2014

Find Trigger with table name in sql server

SELECT
     sysobjects.name AS trigger_name
    ,USER_NAME(sysobjects.uid) AS trigger_owner
    ,s.name AS table_schema
    ,OBJECT_NAME(parent_obj) AS table_name
    ,OBJECTPROPERTY( id, 'ExecIsUpdateTrigger') AS isupdate
    ,OBJECTPROPERTY( id, 'ExecIsDeleteTrigger') AS isdelete
    ,OBJECTPROPERTY( id, 'ExecIsInsertTrigger') AS isinsert
    ,OBJECTPROPERTY( id, 'ExecIsAfterTrigger') AS isafter
    ,OBJECTPROPERTY( id, 'ExecIsInsteadOfTrigger') AS isinsteadof
    ,OBJECTPROPERTY(id, 'ExecIsTriggerDisabled') AS [disabled]
FROM sysobjects INNER JOIN sys.tables t
    ON sysobjects.parent_obj = t.object_id
INNER JOIN sys.schemas
    ON t.schema_id = s.schema_id
WHERE sysobjects.type = 'TR'

Wednesday, August 27, 2014

Link sql server to another sql server

USE [master]
GO

/****** Object:  LinkedServer [Server name or IP]    Script Date: 8/27/2014 4:50:48 AM ******/
EXEC master.dbo.sp_addlinkedserver @server = N'Server name or IP', @srvproduct=N'SQL Server'
 /* For security reasons the linked server remote logins password is changed with ######## */
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'Server name or IP',@useself=N'False',@locallogin=NULL,@rmtuser=N'DB user name',@rmtpassword='paessword'

GO

EXEC master.dbo.sp_serveroption @server=N'Server name or IP', @optname=N'collation compatible', @optvalue=N'false'
GO

EXEC master.dbo.sp_serveroption @server=N'Server name or IP', @optname=N'data access', @optvalue=N'true'
GO

EXEC master.dbo.sp_serveroption @server=N'Server name or IP', @optname=N'dist', @optvalue=N'false'
GO

EXEC master.dbo.sp_serveroption @server=N'Server name or IP', @optname=N'pub', @optvalue=N'false'
GO

EXEC master.dbo.sp_serveroption @server=N'Server name or IP', @optname=N'rpc', @optvalue=N'false'
GO

EXEC master.dbo.sp_serveroption @server=N'Server name or IP', @optname=N'rpc out', @optvalue=N'false'
GO

EXEC master.dbo.sp_serveroption @server=N'Server name or IP', @optname=N'sub', @optvalue=N'false'
GO

EXEC master.dbo.sp_serveroption @server=N'Server name or IP', @optname=N'connect timeout', @optvalue=N'0'
GO

EXEC master.dbo.sp_serveroption @server=N'Server name or IP', @optname=N'collation name', @optvalue=null
GO

EXEC master.dbo.sp_serveroption @server=N'Server name or IP', @optname=N'lazy schema validation', @optvalue=N'false'
GO

EXEC master.dbo.sp_serveroption @server=N'Server name or IP', @optname=N'query timeout', @optvalue=N'0'
GO

EXEC master.dbo.sp_serveroption @server=N'Server name or IP', @optname=N'use remote collation', @optvalue=N'true'
GO

EXEC master.dbo.sp_serveroption @server=N'Server name or IP', @optname=N'remote proc transaction promotion', @optvalue=N'true'
GO


Wednesday, August 13, 2014

Adding DB_executor Role sql server

SQL Server has several fixed database roles such as db_datareader and db_datawriter, which grants the user read and write access respectively to all the tables in the database. Curiously there is no role to grant a user permission to execute stored procedures, but fortunately this is easily resolved by creating a new role.

The following SQL creates the new role in a database, and then grants it execute rights :
-- Create a db_executor role
CREATE ROLE db_executor

-- Grant execute rights to the new role
GRANT EXECUTE TO db_executor
A user can then be added to the new role, much like the db_datareader and db_datawriter roles. 

If you want to check that the role has been created and then add a user to the role, right click on a user in the database in SQL Server Management Studio and select ‘Properties’. In the ‘Database role membership’ control notice that the new db_executor role now appears, click the checkbox to add the user to the role, as below : 

Adding a db_executor role

Alternatively the user can be added to the role in code using the following SQL :
-- to allocate a user to the new role :
EXEC sp_addrolemember 'db_executor','SQLMatters'
A user added to this role will be able to execute all stored procedures in the database, including ones created in the future.

Friday, July 18, 2014

HTTP Error 404.13 - Not Found : The request filtering module is configured to deny a request that exceeds the request content length

Configuring via IISManager

Open the IIS Manager and select the site or application you need to configure in the left panel

Select "Features View" and double click on the "Request Filtering" icon.

 

Figure : Request Filtering

Note :

If you can't find the "Request Filtering"icon, you need to install the IIS Administration Pack from this link : http://www.iis.net/download/AdministrationPack. This is a lightweight installation which shouldn't take too much time on a decent internet speed.

Double clicking on the "Request Filtering"icon will bring up the Request filtering configuration window. Right click on the window and select the "Edit Feature Settings" option:

 

Figure : Edit Feature Settings option in IIS

Finally, specify the Maximum allowable content length (In Byte) in the following window and click "OK" to save:

 

Figure : Specifying Maximum allowable content length in Bytes

This worked perfect for me and I was able to upload the large file now without any problem. Hope, this will work for you too :)

Tuesday, July 15, 2014

SQL SERVER – How to Allow Only Alphabets in Column – Create Check Constraint to Insert Only Alphabets


user can create a check constraint over column to allow insertion of alphabets in the column. Here is a sample script where I demonstrate how users can create constraint over column first so it only allows alphabets.

USE tempdb
GO
-- Create Test tableCREATE TABLE TestTable(ID INT, FirstCol VARCHAR(100),CONSTRAINT FirstCol CHECK (FirstCol NOT LIKE '%[^A-Z]%'))GO-- This will be successfulINSERT INTO TestTable (ID, FirstCol)VALUES (1, 'SQLAuthority')GO-- This will throw an errorINSERT INTO TestTable (ID, FirstCol)VALUES (1, 'SQLAuthority 1')GO-- Clean upDROP TABLE TestTable
GO

Opps Part 1 : Abstraction

  Abstraction in C# is a fundamental concept of object-oriented programming (OOP) that allows developers t...