Posts

Index on view

Let's say if we create index on a view  and if we alter the view then the index gets dropped and again we have to create a index on the view

knowing the server exist or not

Run the command in the command prompt : ping servername -t to know the details

Adding the primary key for two columns

CREATE   TABLE  Persons (     ID int  NOT   NULL ,     LastName varchar( 255 )  NOT   NULL ,     FirstName varchar( 255 ),     Age int, CONSTRAINT  PK_Person  PRIMARY   KEY  (ID,LastName)

Bidirectional Trigger ( Insert in one table and reflected in another table and vice versa)

Concept : Enabling the trigger on first table and enabling the CT on other table to get the table data inserted. /* On first table */     CREATE TRIGGER [dbo].[InsertReportedsoftwareimages]    ON [dbo].[ReportedSoftwareImages]    AFTER INSERT    AS    IF @@ROWCOUNT > 0    BEGIN TRY;    SET NOCOUNT ON ;        -- dbo.SoftwareBuildRecords --------------    MERGE dbo.SoftwareBuildRecords AS tgt    USING (SELECT t.[Changerequestid],t.[softwareimageBuild],t.[softwareimagename], t.IsFoundOnSoftwareImage    FROM INSERTED t inner join    dbo.ChangeRequests_ProblemReport problemReports    ON t.ChangeRequestId = problemReports.Id and t.IsFoundOnSoftwareImage=1) as src    ON ( tgt.[Changerequestid] = src.[Changerequestid]    and tgt.softwareimagename = src.softwareimagename     )    WHEN NO...

CT and CDC Info

Checking CDC SELECT name FROM sys.tables where is_tracked_by_cdc=1 SELECT s.name AS Schema_Name, tb.name AS Table_Name , tb.object_id, tb.type, tb.type_desc, tb.is_tracked_by_cdc FROM sys.tables tb INNER JOIN sys.schemas s on s.schema_id = tb.schema_id WHERE tb.is_tracked_by_cdc = 1 and s.name+'.'+tb.name in ('dbo.areas','dbo.ComponentTags','dbo.Images','dbo.Productlines', 'focalpoint.RadioFrequencyCards','taxman.Chipsets','Masterdata.Components','Masterdata.SoftwareFormats', 'Qswat.Areas','Qswat.Products') order by 1 Enabling CDC on DB : EXEC sys.sp_cdc_enable_db Enabling CDC on Table: EXEC sys.sp_cdc_enable_table  @source_schema = N'dbo',  @source_name   = N'Test', @role_name     = NULL Disable CDC EXEC sys.sp_cdc_disable_table  @source_schema = N'dbo',  @source_name   = N'Test', @capture_instance  =...

Using Where/And in Joins

When Using the inner joins or any kind of joins we can use where/and   Ex : Select * from TableA inner join TableB  on TableA.Id =TableB.Id  Where/and TableA.Id=1 Here we will get the result same whether we use And /where 

Finding User Who Dropped Database Table

Image
CREATE DATABASE TestDB GO USE TestDB GO CREATE TABLE TestTable (ID INT ) GO ALTER TABLE TestTable ADD FirstCol VARCHAR (100) GO DROP TABLE TestTable GO