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 CASE | |
WHEN number % 3 = 0 AND number % 5 = 0 THEN 'FizzBuzz' | |
WHEN number % 3 = 0 THEN 'Fizz' | |
WHEN number % 5 = 0 THEN 'Buzz' | |
ELSE CONVERT(VARCHAR,number) | |
END AS FizzBuzz | |
FROM master.dbo.spt_values | |
WHERE number BETWEEN 1 AND 100 | |
AND type='P' |
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 a.column1 | |
, a.column2 | |
, a.column3 | |
, a.timePeriod | |
, a.column5 | |
FROM schema.tablea a | |
LEFT JOIN schema.tableb AS b ON a.column2 = b.column1 | |
LEFT JOIN schema.tablec AS c ON b.column2 = c.column1 | |
WHERE CONVERT(VARCHAR(8),a.TimePeriod,112) >= @DateParameter |
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
--statistics maintenance | |
--updates anything with more than 2% of changes | |
--or anything not updated within last 30 days | |
--This does full scan, because we have the time in our maintenance window | |
--This should be run after any index rebuilding as a statistics should get a update with a full scan | |
--Sidenote: If you have partitioned indexes and are running SQL 2012 or later, you should read up on how a index rebuild does not use fullscan | |
--And if you are using paritions, and switching partitions, you also may need to manually update your statistics | |
SET NOCOUNT ON; |
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
--statement 2 | |
DECLARE @a2 int; | |
DECLARE @b2 bit; | |
DECLARE @c2 varchar(50); | |
SET @a2 = 1989834; | |
SET @b2 = 0; | |
SET @c2 = 'Testing'; | |
SELECT @a2, @b2, @c2; |
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
--statement 1 | |
DECLARE @a int, @b bit, @c varchar(50); | |
SET @a = 1989834; | |
SET @b = 0; | |
SET @c = 'Testing'; | |
SELECT @a, @b, @c; |
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
IF EXISTS(SELECT * FROM tempdb..sysobjects WHERE id = object_id('tempdb..#t_users')) | |
drop table #t_users | |
CREATE TABLE #t_users ( [name] SYSNAME) | |
INSERT #t_users ( [name] ) | |
SELECT [name] | |
FROM sysusers | |
WHERE | |
islogin = 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
SELECT o.name AS "Table Name", i.rowcnt AS "Row Count" | |
FROM sysobjects o, sysindexes i | |
WHERE i.id = o.id | |
AND indid IN(0,1) | |
AND xtype = 'u' | |
AND o.name <> 'sysdiagrams' | |
ORDER BY i.rowcnt DESC | |
COMPUTE SUM(i.rowcnt) |
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
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script><script type="text/javascript"> | |
$(function(){ | |
$("table").css("width", "100%"); | |
}); | |
</script> |
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
--updated 6/27/2014 to include schema for each object | |
SELECT table_name AS [Table], column_name AS [Column], table_schema as [schema] | |
FROM information_schema.columns | |
WHERE column_name like '%' + @var + '%' | |
ORDER BY table_name, column_name | |
SELECT table_name as viewname, TABLE_SCHEMA as [schema] | |
FROM information_schema.views | |
WHERE view_definition like '%' + @var + '%' |
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
declare @SourceDB varchar(128) | |
set @sourceDB = 'jivesbs' | |
declare @sql varchar(128) | |
create table #tables(name varchar(128)) | |
select @sql = 'insert #tables select TABLE_NAME from ' + @SourceDB + '.INFORMATION_SCHEMA.TABLES where TABLE_TYPE = ''BASE TABLE''' | |
exec (@sql) | |
create table #SpaceUsed (name varchar(128), rows varchar(11), reserved varchar(18), data varchar(18), index_size varchar(18), unused varchar(18)) |
NewerOlder