Skip to main content

Posts

Showing posts from August, 2011

Find in which objects a particular word is used

Sometimes you have situation, where in you want to figure out which function a particular word / object is used in.  You can use the following query for this purpose. This query is useful if you want to search in which function a particular table is being used.    SELECT   OBJECT_NAME(id), TEXT    FROM     syscomments    WHERE    [text] LIKE '%proc_name%'   --          AND OBJECTPROPERTY(id, 'IsProcedure') = 1 You can also use this query for the purpose    SELECT *    FROM   sysobjects     WHERE name LIKE '%email%'

Find the Table Name

Ever came across a situation where you know a column name but don't remember the table name. This is the third incident that i forgot the table name and so thought of penning it down. How I Solved It? I will just share the queries that will help you get this done. I am sure that would be more than enough. Query 1:                              SELECT  *                              FROM    sys.columns                              WHERE   name LIKE   '%column_name%' This query will give you list of object_id and names that has the column name in it Using the object id we can find the object. Query 2:                              SELECT  *                              FROM    sys.objects                              WHERE   object_id IN  (..., ... , obejct ids from query 1..., ...) This query will give you the object name and type.  The object of type U are user tables. These tables are list of tables that have the column that we we were looking for

Insufficient access rights to perform the operation. (Exception from HRESULT: 0x80072098)

While accessing the active directory (AD) and authorization manager (AZMAN) , If you get “   Insufficient access rights to perform the operation. (Exception from HRESULT: 0x80072098)  “ message check the    account that is being used to get the LDAP query from AD .  ERROR DETAILS Exception Details:  System.Runtime.InteropServices.COMException: Insufficient access rights to perform the operation. (Exception from HRESULT: 0x80072098) Source Error: Line 154:    'Session("FullName") = System.Security.Principal.WindowsIdentity.GetCurrent.Name.ToString() Line 155: Line 156:    If Not User.IsInRole("Role1") Then Line 157:          Response.Redirect("./Login.aspx") Line 158:    End If  Stack Trace : .... SOLVE IT Steps to do check the app pool rights: Click on the website name that you are having problem with in IIS  In the right panel you will see 'Basic Settings'. Click It. Select the specific pool option and enter the name of the ac

Whats up with identity_insert ?

Basics: To insert explicit value in the identity column of a table we need to set identity_insert On. Syntax for this is SET IDENTITY_INSERT tablename ON Now execute all your insert / update queries Make sure you set the identity_insert to Off. Syntax for this is SET IDENTITY_INSERT tablename OFF Did you know: Identity insert is session sensitive . If you have an identity_insert On for another table in that session you will get the message " IDENTITY_INSERT is already ON for table 'xxx'. Cannot perform SET operation for table 'tablename'." To test this you can open another session and try executing the same statement again. You will not get the error message this time. Option 2: Step 1: Go to the Table name in the Object Explorer and click on Design. Step 2: In column Properties, go to 'Identity Specification' and select 'Is identity' as 'No' Step 3: Click on Save. Now try the insert/update command. Still does not 

Get List of Triggers In Database

To get a list of TRIGGERS in SQL database use : SELECT      S2.[name] TableName     , S1.[name] TriggerName     , CASE      WHEN S1.deltrig > 0         THEN 'Delete'     WHEN S1.instrig > 0          THEN 'Insert'     WHEN S1.updtrig > 0          THEN 'Update'     END 'TriggerType'  FROM sysobjects S1 JOIN sysobjects S2  ON S1.parent_obj = S2.[id]  WHERE S1.xtype='TR' Want more Detail? Use : SELECT      S2.[name] TableName     , S1.[name] TriggerName     , CASE          WHEN S2.deltrig = s1.id              THEN 'Delete'          WHEN S2.instrig = s1.id              THEN 'Insert'          WHEN S2.updtrig = s1.id              THEN 'Update'      END 'TriggerType'      , 'S1'     ,s1.*     ,'S2'     ,s2.*  FROM sysobjects S1  JOIN sysobjects S2  ON S1.parent_obj = S2.[id]  WHERE S1.xtype='TR'