This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT o.name AS [Table_Name] | |
, x.name AS [Index_Name] | |
, i.partition_number AS [Partition] | |
, i.index_id AS [Index_ID] | |
, x.type_desc AS [Index_Type] | |
, i.leaf_update_count * 100.0/ ( i.range_scan_count + i.leaf_insert_count + i.leaf_delete_count | |
+ i.leaf_update_count + i.leaf_page_merge_count + i.singleton_lookup_count) AS [Percent_Update] | |
, i.range_scan_count * 100.0/ ( i.range_scan_count + i.leaf_insert_count + i.leaf_delete_count | |
+ i.leaf_update_count + i.leaf_page_merge_count + i.singleton_lookup_count) AS [Percent_Scan] | |
FROM sys.dm_db_index_operational_stats(DB_ID(), NULL, NULL, NULL) i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* returns all partitioned tables: */ | |
SELECT OBJECT_NAME(p.[object_id]) AS 'TableName' | |
, i.[name] AS 'IndexName' | |
, i.index_id | |
, p.[object_id] | |
, au.data_space_id | |
, p.partition_number | |
, p.hobt_id | |
, partitionds.name AS partition_filegroup | |
INTO #partDist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EXEC master.dbo.xp_restore_database @database = '', @filename = '' | |
, @filegroup = '', @encryptionkey = N'IMMAENCRYPTCHYU', @with = 'RECOVERY' | |
, @with = 'MOVE '''' TO ''''', @returndetails = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EXEC master.dbo.xp_restore_database @database = '', @filename = '' | |
, @encryptionkey = N'IMMAENCRYPTCHYU', @read_write_filegroups = 1 | |
, @with = 'RECOVERY', @returndetails = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EXEC master.dbo.xp_restore_database @database = '', @filename = '' | |
, @encryptionkey = N'IMMAENCRYPTCHYU', @read_write_filegroups = 1 | |
, @with = 'NORECOVERY', @returndetails = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EXEC master.dbo.xp_backup_database @database = '', @filename = 'Y:\SQL_BACKUPS\' | |
, @compressionlevel = 4, @cryptlevel = 8, @encryptionkey = N'IMMAENCRYPTCHYU' | |
, @read_write_filegroups = 1, @verify = 1, @returndetails = 1 | |
, @init = 1, @with = 'CHECKSUM', @with = 'DIFFERENTIAL'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EXEC master.dbo.xp_backup_database @database = '<database name>', @filename = 'Y:\SQL_BACKUPS\<name of backup file>' | |
, @compressionlevel = 4, @cryptlevel = 8, @encryptionkey = N'IMMAENCRYPTCHYU' | |
, @read_write_filegroups = 1, @verify = 1, @returndetails = 1, @init = 1, @with = 'CHECKSUM'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EXEC master.dbo.xp_backup_database @database = '<database name>', | |
@filename = 'Y:\SQL_BACKUPS\<name of backup file>', @filegroup = '<filegroup to backup>' | |
, @compressionlevel = 4, @cryptlevel = 8, @encryptionkey = N'IMMAENCRYPTCHYU' | |
, @verify = 1, @returndetails = 1, @init = 1, @with = 'CHECKSUM'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UPDATE DW_DBNAME.dbo.DW_TABLE | |
SET ETL_JOB_SEQ_NUM = 1027140 , | |
ETL_IUD_CD = 'D' , | |
ETL_UPD_DTM = CONVERT(DATETIME, '03/16/2016 01:01:17') | |
WHERE ETL_VERS_START_DTM = CONVERT(DATETIME, '12/27/2014 00:26:24.137') | |
AND ACCT_NO = '5001194157' | |
AND ACCT_TYPE = 'ILN'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* A pivoted list of contacts */ | |
WITH contactsCTE AS (SELECT a.acctNo | |
, c.name | |
, c.email | |
, ROW_NUMBER() OVER (PARTITION BY a.acctNo ORDER BY c.ContactID) AS ConNumber | |
FROM contacts c JOIN accounts a ON a.acctNo = c.acctNo) | |
SELECT acctNo | |
, MIN(name1) AS Name1 | |
, MIN(email1) AS Email1 | |
, MIN(name2) AS Name2 |