Truncate Log in Database Mirroring SQL Server 2008 2012

select log_reuse_wait_desc from sys.databases where name = 'AdventureWorks' If Output is "LOG_BACKUP" -- Execute 2 Times just in case -- BACKUP LOG AdventureWorks TO DISK='NUL:' -- Now Truncate the Log -- USE AdventureWorks GO ALTER DATABASE AdventureWorksSET RECOVERY SIMPLE WITH NO_WAIT; GO DBCC SHRINKFILE(AdventureWorks_LOG, 100); GO ALTER DATABASE AdventureWorks SET RECOVERY FULL WITH NO_WAIT; GO

Stored Procedure to Insert Data SQL Server

CREATE TABLE [dbo].[MASTER]( [BANK_CODE] [varchar](30) NULL, [TRNX_UID] [float] NULL, [CARD_TYPE] [varchar](30) NULL, [DIR_FLAG] [varchar](30) NULL, [ACQ_CODE] [varchar](30) NULL, [ACQ_DESC] [varchar](200) NULL, [ISS_CODE] [varchar](30) NULL, [ISS_DESC] [varchar](200) NULL, [TRNX_STATUS] [varchar](30) NULL, [TRNX_TYPE] [varchar](30) NULL, [TERMINAL_ID] [varchar](200) NULL, [CARD_NO] [varchar](100) NULL, [CURRENCY_CODE] [varchar](30) NULL, [AMOUNT_FC] [numeric](20, 6) NULL, [AMOUNT_LC] [numeric](20, 2) NULL, [CURRENCY_RATE] [numeric](10, 6) NULL, [TRNX_DATE] … Continue reading Stored Procedure to Insert Data SQL Server

Using PowerShell to send a Windows Service Recovery Email Alert

Thom's HeadSpace

recovery dialogue boxEach Service that runs in Windows features a Recovery tab in the Services.msc management console. Normally I only ever set this up to restart the service after 5 minutes in case something had conflicted with it’s initial start-up attempt. However, we recently had a problem with an IBM service that caused our Windows 2003 R2 x64 server to reboot if it crashed. I thought it would be very handy if we could get an email sent to the IT department if the service was failing. I had dabbled with using BLAT in the past but seeing as all of our servers already have PowerShell installed I thought that would be a more efficient option.

View original post 433 more words

Create Indexed Views in SQL Server; SQL Equivalent of Oracle Materialized Views.

SQL Server supports creating indexes on a view. It is the same concept as Materialized Views in Oracle. The main difference in the syntax in normal views and indexed views is the clause "with schemabinding" CREATE VIEW [dbo].[ViewName] with schemabinding AS SELECT id, activityID, userID, value, date FROM dbo.TableName WHERE (field = 'activityID') Now you … Continue reading Create Indexed Views in SQL Server; SQL Equivalent of Oracle Materialized Views.