Ads

02 August 2013

DBCC

More on :- http://msdn.microsoft.com/en-us/library/ms188796.aspx

Handy Information :-

Database Console Command statements are grouped into the following categories.
Command category Perform
Maintenance Maintenance tasks on a database, index, or filegroup.
Miscellaneous Miscellaneous tasks such as enabling trace flags or removing a DLL from memory.
Informational Tasks that gather and display various types of information.
Validation Validation operations on a database, table, index, catalog, filegroup, or allocation of database pages.
---------------------------------------------------------------------------
DBCC commands take input parameters and return values. All DBCC command parameters can accept both Unicode and DBCS literals.

 DBCC Internal Database Snapshot Usage

The following DBCC commands operate on an internal read-only database snapshot that the Database Engine creates. This prevents blocking and concurrency problems when these commands are executed. For more information, see Database Snapshots (SQL Server).
DBCC CHECKALLOC DBCC CHECKDB
DBCC CHECKCATALOG DBCC CHECKFILEGROUP
DBCC CHECKTABLE
When you execute one of these DBCC commands, the Database Engine creates a database snapshot and brings it to a transactionally consistent state. The DBCC command then runs the checks against this snapshot. After the DBCC command is completed, this snapshot is dropped.
Sometimes an internal database snapshot is not required or cannot be created. When this occurs, the DBCC command executes against the actual database. If the database is online, the DBCC command uses table-locking to ensure the consistency of the objects that it is checking. This behavior is the same as if the WITH TABLOCK option were specified.
An internal database snapshot is not created when a DBCC command is executed:
  • Against master, and the instance of SQL Server is running in single-user mode.
  • Against a database other than master, but the database has been put in single-user mode by using the ALTER DATABASE statement.
  • Against a read-only database.
  • Against a database that has been set in emergency mode by using the ALTER DATABASE statement.
  • Against tempdb. In this case, a database snapshot cannot be created because of internal restrictions.
  • Using the WITH TABLOCK option. In this case, DBCC honors the request by not creating a database snapshot.
The DBCC commands use table locks instead of the internal database snapshots when the command is executed against the following:
  • A read-only filegroup
  • An FAT file system
  • A volume that does not support 'named streams'
  • A volume that does not support 'alternate streams'
Note Note
Trying to run DBCC CHECKALLOC, or the equivalent part of DBCC CHECKDB, by using the WITH TABLOCK option requires a database X lock. This database lock cannot be set on tempdb or master and will probably fail on all other databases.
Note Note
DBCC CHECKDB fails when it is run against master if an internal database snapshot cannot be created.
The sys.dm_exec_requests catalog view contains information about the progress and the current phase of execution of the DBCC CHECKDB, CHECKFILEGROUP, and CHECKTABLE commands. The percent_complete column indicates the percentage complete of the command, and the command column reports the current phase of the execution of the command.
The definition of a unit of progress depends on the current phase of execution of the DBCC command. Sometimes progress is reported at the granularity of a database page, in other phases it is reported at the granularity of a single database or allocation repair. The following table describes each phase of execution, and the granularity at which the command reports progress.
Execution phase Description Progress reporting granularity
DBCC TABLE CHECK The logical and physical consistency of the objects in the database is checked during this phase. Progress reported at the database page level.
The progress reporting value is updated for each 1000 database pages that are checked. 
DBCC TABLE REPAIR Database repairs are performed during this phase if REPAIR_FAST, REPAIR_REBUILD, or REPAIR_ALLOW_DATA_LOSS is specified, and there are object errors that must be repaired. Progress reported at the individual repair level.
The counter is updated for each repair that is completed.
DBCC ALLOC CHECK Allocation structures in the database are checked during this phase.
Note Note
DBCC CHECKALLOC performs the same checks.
Progress is not reported
DBCC ALLOC REPAIR Database repairs are performed during this phase if REPAIR_FAST, REPAIR_REBUILD, or REPAIR_ALLOW_DATA_LOSS is specified, and there are allocation errors that must be repaired. Progress is not reported.
DBCC SYS CHECK Database system tables are checked during this phase. Progress reported at the database page level.
The progress reporting value is updated for every 1000 database pages that are checked.
DBCC SYS REPAIR Database repairs are performed during this phase if REPAIR_FAST, REPAIR_REBUILD, or REPAIR_ALLOW_DATA_LOSS is specified, and there are system table errors that must be repaired. Progress reported at the individual repair level.
The counter is updated for each repair that is completed.
DBCC SSB CHECK SQL Server Service Broker objects are checked during this phase.
Note Note
This phase is not executed when DBCC CHECKTABLE is executed.
Progress is not reported.
DBCC CHECKCATALOG The consistency of database catalogs are checked during this phase.
Note Note
This phase is not executed when DBCC CHECKTABLE is executed.
Progress is not reported.
DBCC IVIEW CHECK The logical consistency of any indexed views present in the database is checked during this phase. Progress reported at the level of the individual database view that is being checked.

Features Supported by the Editions of SQL Server 2012

Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "SQL_Latin1_General_CP1_CS_AS" in the equal to operation




  • Collation was missing on the column which is highlighted, added the same and worked smoothly.

25 July 2013

Running Batch File Using T-SQL

DECLARE @PassedVariable VARCHAR(100)
DECLARE @CMDSQL VARCHAR(1000)
SET @PassedVariable = 'SqlAuthority.com'
SET @CMDSQL = 'c:findword.bat' + @PassedVariable
EXEC master..xp_CMDShell @CMDSQL




more on :- http://blog.sqlauthority.com/2007/06/27/sql-server-running-batch-file-using-t-sql-xp_cmdshell-bat-file/
 

16 July 2013

Replication - Between 2005 and 2008

Using a SQL Server 2005 or SQL Server 2008 Distributor with a Publisher Running SQL Server 2000

SQL Server 2005 and SQL Server 2008 can be used as a remote Distributor for Publishers that are running SQL Server 2000. To change agent properties in this scenario, execute the following stored procedures at the Distributor. These procedures let you change properties that were introduced in SQL Server 2005:
If you have a Publisher and Distributor that are running SQL Server 2000, you can change the credentials under which agents make connections by using sp_changedistpublisher and sp_changesubscriber. However, if you upgrade the Distributor to SQL Server 2008, these procedures cannot be used to change the credentials that are used in existing agent jobs. The procedures do affect agent jobs that are created after the procedure is called. To change the credentials for existing agent jobs, call one of the four procedures listed previously.

IMP :-

SQL Server 2000 and SQL Server 2005 can both participate in replication topologies with SQL Server 2008. For SQL Server 2000 the minimum version is Service Pack 3 (SP3). For SQL Server 2005 the minimum version is Service Pack 2 (SP2).
When you replicate between or among different versions of SQL Server, you are usually limited to the functionality of the earliest version used. For example, if you upgrade a Distributor to an instance of SQL Server 2008, but you have a Publisher that is running an instance of SQL Server 2005 and a Subscriber that is running an instance of SQL Server 2000, you are limited to the general functionality and replication functionality of SQL Server 2000.
NoteNote
Because the SQL Server on-disk storage format is the same in the 64-bit and 32-bit environments, a replication topology can combine server instances that run in a 32-bit environment and server instances that run in a 64-bit environment.
For all types of replication, the Distributor version must be no earlier than the Publisher version. (Frequently, the Distributor is the same instance as the Publisher.)
For transactional replication, a Subscriber to a transactional publication can be any version within two versions of the Publisher version. For example, a SQL Server 2000 Publisher can have SQL Server 2008 Subscribers, and a SQL Server 2008 Publisher can have SQL Server 2000 Subscribers.
For merge replication, a Subscriber to a merge publication can be any version no later than the Publisher version. For more information about compatibility for earlier versions, see "Compatibility Level for Merge Publications" later in this topic. For more information about replication features that are supported in the various editions of SQL Server, see Features Supported by the Editions of SQL Server "Denali".

04 July 2013

.TUF file

TUF file is a Microsoft SQL Server Transaction Undo file. .TUF File contains the information regarding any modifications that were made as part of incomplete transactions at the time the backup was performed.

A transaction undo(.TUF) file is required if a database is loaded in read-only state. In this state, further transaction log backups may be applied.

if  .TUF file is deleted then log shipping restoration job will not work.


01 July 2013

OLE DB error: OLE DB or ODBC error: You do not have permission to run 'SP_TRACE_CREATE'.; 42000

OLE DB error: OLE DB or ODBC error: You do not have permission to run 'SP_TRACE_CREATE'.; 42000

 

Answer:- 

 

USE master
GO
GRANT ALTER TRACE TO [LOGINNAME]
GO