Saturday, 14 September 2013

Disable DTS package task and reschedule DTS job.

Problem

How you can disable task from DTS package and reschedule job.

Solution

Why reschedule job required after DTD package change?
When DTS package change system automatically generates new GUID, hence rescheduling of job required.

My DTS package name PropertyDM

Steps

     1.  Login to server and open Enterprise Manager (SQL server 2000)

     2.  Open Data Transformation Service.

     3. Click Local Packages.



     4. Right Click PropertyDM DTS Package and click Design Package.



    5. Right Click step (to Disable) workflow properties




     6.  New Window appeared, now go to options tab--> check the disable this step     
        checkbox...
        Click OK.



     7. Save the changes
     
     8. Open Management-->Sql Server Agent-->Jobs 



     9.  Right Click PropertyDM job --> Select Delete 
    
   

 10. Click Local Packages 
   
 11.Right Click PropertyDM DTS Package and click Schedule Package. 



   12.  New window appeared.  
   
  13. Change Occurs once at:  12:29 AM(Schedule Time) click OK button.


I hope this helps you to disable DTS package task.

Monday, 9 September 2013

Microsoft SQL Server: Monitoring SQL Server Error Log

Microsoft SQL Server: Monitoring SQL Server Error Log

Monitoring SQL Server Error Log

Reviewing SQL server ERROR.LOG can be a long and time consuming task ,if you are managing multiple SQL Server installations. However you usually need to see only the error information and not the informational entries. This article will help you with tracking the important information from the errorlog.
To accomplish this task here is what I've done.
  1. Create a table to hold all the data from current ERROR.LOG
  2. Truncate table and upload the current ERROR.LOG
  3. Create Store procedure and Execute to analyze the data and produce an output with only error type information
-- Create a table

USE [DBAmantanence]
GO
CREATE TABLE [dbo].[ErrLogData](
 [LogID] [int] IDENTITY(1,1) NOT NULL,
 [LogDate] [datetime] NULL,
 [ProcessInfo] [nvarchar](50) NULL,
 [LogText] [nvarchar](4000) NULL,
 [SQLServerName] [nvarchar](150) NULL,
PRIMARY KEY CLUSTERED
(
 [LogID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO


Now we create store procedure to clear the table and insert the ERROR.LOG data into the table.

USE [DBAmantanence]
GO
 SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 Create PROCEDURE Proc_ErrLogData
          
AS
BEGIN
               
                SET NOCOUNT ON;

 IF EXISTS (SELECT * FROM [dbo].[ErrLogData])
 BEGIN
 TRUNCATE TABLE [dbo].[ErrLogData]
 END
 DECLARE @SQLCmd VARCHAR(1024)
 SELECT @SQLCmd = 'Insert Into dbo.ErrLogData (LogDate, ProcessInfo, LogText) Exec master..xp_readerrorlog '
 EXEC (@SQLCmd)

-- Cycle through the ErrLogData table and insert the server's name
DECLARE SrvName_Cursor CURSOR FOR
 SELECT [SQLServerName] FROM [dbo].[ErrLogData] WHERE [SQLServerName] IS NULL
 OPEN SrvName_Cursor
 FETCH NEXT FROM SrvName_Cursor
 WHILE @@FETCH_STATUS = 0
 BEGIN
 UPDATE [dbo].[ErrLogData] SET [SQLServerName] = @@servername
 FETCH NEXT FROM SrvName_Cursor
 END
CLOSE SrvName_Cursor
DEALLOCATE SrvName_Cursor

END
GO

Now execute store procedure

EXEC [dbo].[Proc_ErrLogData]

Now we can analyze the data collected with a query. Modify the WHERE clause to show more or less data.

USE [DBAmantanence]
GO

SELECT [LogID]
 ,[LogDate]
 ,[ProcessInfo]
 ,[LogText]
 ,[SQLServerName]
FROM [dbo].[ErrLogData]
WHERE ([logtext] NOT LIKE '% found 0 errors %'
 AND [logtext] NOT LIKE '%\ERRORLOG%'
 AND [logtext] NOT LIKE '%Attempting to cycle errorlog%'
 AND [logtext] NOT LIKE '%Errorlog has been reinitialized.%'
 AND [logtext] NOT LIKE '%found 0 errors and repaired 0 errors.%'
 AND [logtext] NOT LIKE '%without errors%'
 AND [logtext] NOT LIKE '%This is an informational message%'
 AND [logtext] NOT LIKE '%Setting database option ANSI_WARNINGS%'
 AND [logtext] NOT LIKE '%Error: 15457, Severity: 0, State: 1%'
 AND [logtext] NOT LIKE '%finished without errors%')
ORDER BY [SQLServerName] ,[LogID]
GO


Here is a sample output from the script above.



You can create a scheduled job to automatically populate the table with error logs of all your SQL servers, which helps when you to review an issue that effects other SQL Servers.

I hope this helps in your ability to review the ERROR.LOG file for your SQL servers.

Saturday, 7 September 2013

User Defined Server Roles

New Administration features in SQL server 2012

SQL Server 2012 SQL Server allows roles to be created at the server level. 
This can be done through the CREATE/ALTER/DROP SERVER ROLE commands,
or through the GUI with a right-click on the Server Roles node, new menu item has appeared below refer screenshot.



This brings up a new dialog box below refers screenshot.


The temporary DBA's login is added to the new server role to give them the restricted set of sysadmin permissions, using  below code:

USE master
GO
CREATE SERVER ROLE TEMPDBAROLE AUTHORIZATION sa
GRANT VIEW SERVER STATE TO TEMPDBAROLE
GRANT VIEW ANY DATABASE TO TEMPDBAROLE
GRANT VIEW ANY DEFINITION TO TEMPDBAROLE
DENY ALTER TRACE TO TEMPDBAROLE
ALTER SERVER ROLE TEMPDBAROLE ADD MEMBER temp_dbas

Contained databases in SQL server 2012


New Administration features in SQL server 2012

Contained databases

Contained databases are a new concept in SQL Server 2012. Currently if you want to move database one server to another server or even one instance to another, most cases the applications that are associated with it cannot use it immediately, even if that database is a secondary database or mirror for the principal.
You have to create Logins, scheduled jobs and endpoints and are sometimes not identified until a problem occurs.
In simple terms it is a database that is isolated from other databases, and isolated from the instance of SQL Server that is hosting the database.


There are four ways that SQL Server 2012 helps to isolate databases from the instance:
  • Much of the metadata that describes a database is maintained in the database and not in the master database
  • All metadata is defined using the same collation
  • User authentication can be performed by the database, reducing the database’s dependency on the logins of the instance of SQL Server
  • The SQL Server environment reports, DMVs and xEvents can act upon containment information.

Why do we need Contained Databases?


SQL Server security has always managed at two levels:















Logins are managed at Server level, and users are managed at Database level. This means permissions for SQL Server have to be defined in two or more locations, and this can cause confusion.
Manage logins and users separately can cause problems when it comes to maintaining high availability and disaster recovery solutions and the need to regularly synchronise logins against failover and secondary servers; to avoid problems such as orphaned users.
So with the introduction of containment and the concept of boundaries in SQL Server 2012; a database can become free of external dependencies, server level metadata, settings and security logins.

Microsoft has provided a DMV that lists any objects that do not comply with containment rules for the current database.

SELECT object_name (major_id), *
FROM sys.dm_db_uncontained_entities

Making an existing database partially contained

Step1.  Make a SQL Server instance level change to allow a contained database to authenticate with the database engine.

sp_configure 'contained database authentication', 1
reconfigure

Step2. If you intend to use the GUI tools to change the containment type, you will need to kill all connections to the database that you want to make partially contained. Note that this is only necessary when taking a database from non-contained to partially contained; setting it back to non-contained does not require this step, nor does it apply if you use T-SQL to change the containment mode to partial.
Step3.  Set the database to partially contained mode.

ALTER DATABASE test
SET containment = PARTIAL

For revert
           
                        SET containment = NONE

It can be performed through the GUI tools.




















Migrating your logins to a contained database

After existing database has been converted to a contained database, you are left with the task of migrating your logins. These logins can be easily migrated to a partially contained database level using the Below T-SQL code:

DECLARE @UserName sysname
DECLARE csrUsers cursor
FOR
SELECT dbprin.name
FROM sys.database_principals AS dbprin
INNER JOIN
sys.server_principals AS svrprin
ON dbprin.sid = svrprin.sid
WHERE dbprin.authentication_type = 1
AND svrprin.is_disabled = 0
OPEN csrUsers
FETCH NEXT
FROM csrUsers
INTO @UserName
WHILE @@fetch_status = 0
BEGIN
exec sp_migrate_user_to_contained
@username = @UserName,
@rename = N'keep_name',
@disablelogin = N'disable_login'
-- disable the server level login
FETCH NEXT
FROM csrUsers
INTO @UserName
END
CLOSE csrUsers
DEALLOCATE csrUsers

Friday, 6 September 2013

Columnstore Indexes

SQL Server 2012 has a new method of storing nonclustered indexes. This is an index created just like any other, but it stores index data in a highly compressed, column-wise fashion. For certain classes of queries, particularly those found in Kimball-design star schemas, columnstore indexes make a lot of sense. Columnstore indexes can speed up data warehousing queries by a large factor, from 10 to even 100 times!

·         A columnstore index is just another nonclustered index on a table.
·         Columnstore indexes use their own compression algorithm; you cannot use row or page compression on a columnstore index.
·         Columnstore indexes accelerate data warehouse queries but are not suitable for OLTP workloads. Because of the row reconstruction issues, tables containing a columnstore index become read only. If you want to update a table with a columnstore index, you must first drop the columnstore index. If you use table partitioning, you can switch a partition to a different table without a columnstore index, update the data there, create a columnstore index on that table (which has a smaller subset of the data), and then switch the new table data back to a partition of the original table.

There are three new catalog views you can use to gather information about columnstore indexes:

·         sys.column_store_index_stats
·         sys.column_store_segments
·         sys.column_store_dictionaries

The columnstore index is divided into units called segments. Segments are stored as large objects, and consist of multiple pages. A segment is the unit of transfer from disk to memory. Each segment has metadata that stores the minimum and maximum value of each column for that segment. This enables early segment elimination in the storage engine. SQL Server loads only those segments requested by a query into memory.

Creating a columnstore index

CREATE TABLE #Customer
(
CustomerName varchar(200) NULL,
DateOfBirth datetime NULL,
Sex char(10) NULL,
Salary int NULL,
LoanAmount int NULL
)

You can specify only those columns you want to include, you would usually create a columnstore index across all of the columns.

CREATE NONCLUSTERED COLUMNSTORE INDEX csidxCustomer
ON #Customer (CustomerName, DateOfBirth, Sex, Salary, LoanAmount)

To drop a columnstore index

DROP INDEX #Customer.csidxCustomer

Disabling a columnstore index

ALTER INDEX csidxCustomer ON #Customer DISABLE


To rebuilding the index


ALTER INDEX csidxCustomer ON #Customer REBUILD

It is possible that under low memory conditions the below error might be seen:

Low memory condition:
The statement has been terminated.
Msg 8645, Level 17, State 1, Line 1
A timeout occurred while waiting for memory resources to execute the
query in resource pool 'default' (2).
Rerun the query.