Monday, October 1, 2012

Best Practices for Installing SQL Server 2008 R2


Recommendations For Installing
      ¨  Use NTFS file system
      ¨  Do not install on a compressed drive
      ¨  Do not install SQL Server on a Domain Controller
      ¨  Requires setup administrative privileges

Software Requirements
      ¨  .Net Framework 3.5 SP1
      ¨  Windows Installer 4.5 or later
      ¨  Internet Explorer 6 SP1
      ¨  PowerShell
      ¨  Visual Studio 2008 SP1 prior to run SQL Server setup

Hardware Requirements
      ¨  At least 3.6 GB Hard Disk
      ¨  Memory                              Min        Recommended                
                  ¡  Datacenter             1 GB       4 GB or more                    
                  ¡  Entrprise                 1 GB       4 GB or more                    
                  ¡  Standard                 1 GB       4 GB or more

¨  CPU
                  ¡  2 GHz or Faster

¨  Supported Operating Systems.
                  ¡  All Edition
                              ú  Windows Server 2008 Standard or higher
                              ú  Windows Server 2003 Standard SP2 or higher

¡  Developer and Express
                              ú  Windows XP Professional SP2 or higher
                              ú  Windows Vista Home Basic or higher

¨  1024 x 768 video resolution.

Tuesday, May 29, 2012

Update Trigger

Update Trigger for update the specific column
Create Update Trigger to update a one particular column in the table while updating the record.
According to the specific value of another column we are updating the other column.

Create new table

CREATE TABLE [dbo].[CustomerInvoice](
      [InvoiceID] [int] IDENTITY(1,1) NOT NULL,
      [InvoiceDate] [date] NULL,
      [InvoiceAmount] [numeric](10, 2) NULL,
      [PaidAmount] [numeric](10, 2) NULL,
      [BalanceAmount] [numeric](10, 0) NULL,
      [InvoiceSetteled] [bit] NULL,
 CONSTRAINT [PK_InvoiceMaster] PRIMARY KEY CLUSTERED
(
      [InvoiceID] ASC
))

GO

Some records for Invoice data before update


Create Trigger
CREATE TRIGGER UpdateSetteledStatus ON dbo.CustomerInvoice
AFTER UPDATE
AS
BEGIN
  SET NOCOUNT ON;
  DECLARE @InvID int
  IF (UPDATE(BalanceAmount))
    BEGIN
      SELECT @InvID = InvoiceID FROM INSERTED
      IF(SELECT BalanceAmount FROM dbo.CustomerInvoice WHERE InvoiceID = @InvID)
         = 0
            UPDATE dbo.CustomerInvoice SET InvoiceSetteled = 1 WHERE InvoiceID =
            @InvID
    END
END
GO


Update one record in the table
UPDATE dbo.CustomerInvoice SET PaidAmount = 2800,BalanceAmount = 0 where InvoiceID = 3
Updating the record after settled the Invoice, as PaidAmount = InvoiceAmount and BlanceAmount = 0.  
After update check the below records.

 



In this case after update this perticular record with Balance Amount as 0 and UPDATE TRIGGER has fired and update the InvoiceSettled column as 1.