Skip to content

Instantly share code, notes, and snippets.

@veysby
veysby / gist:9523147395b00ba441d6
Created October 11, 2014 12:34
MSSQL: list schema tables, indexes, etc
SELECT
t .NAME AS TableName,
i .name as indexName,
p .[Rows],
sum(a .total_pages) as TotalPages ,
sum(a .used_pages) as UsedPages ,
sum(a .data_pages) as DataPages ,
(sum( a.total_pages ) * 8) / 1024 as TotalSpaceMB,
(sum( a.used_pages ) * 8) / 1024 as UsedSpaceMB,
(sum( a.data_pages ) * 8) / 1024 as DataSpaceMB
@veysby
veysby / gist:2f15661eac5d4aff2698
Created October 11, 2014 12:45
SH: script base folder
`cd $(dirname $0) && pwd`
@veysby
veysby / gist:3481683ccadbdb19b5de
Last active August 29, 2015 14:10 — forked from sgergely/gist:3793166
Hints: Midnight Commander on Mac
----- Esc -----
Quick change directory: Esc + c
Quick change directory history: Esc + c and then Esc + h
Quick change directory previous entry: Esc + c and then Esc + p
Command line history: Esc + h
Command line previous command: Esc + p
View change: Esc + t (each time you do this shortcut a new directory view will appear)
Print current working directory in command line: Esc + a
Switch between background command line and MC: Ctrl + o
Search/Go to directory in active panel: Esc + s / Ctrl + s then start typing directory name
@veysby
veysby / gist:e07fbd134f5482018319
Created December 9, 2014 04:42
Hints: Eclipse | STS on Mac
Key Bingings - Eclipse / Spring Source Tool Suite
Source: http://zeroturnaround.com/rebellabs/top-java-ide-keyboard-shortcuts-for-eclipse-intellij-idea-netbeans/
Eclipse STS
SEARCH
Find Usages ⌘ + Shift + G ⌘ + Shift + G
Find / Replace in file ⌘ + F ⌘ + F
Find / Replace in projects Ctrl + H Ctrl + H
Find next ⌘ + K ⌘ + K
@veysby
veysby / gist:4f18e99d206121ee33a6
Created January 27, 2015 16:38
MSSQL: list statistics update date
SELECT
SCHEMA_NAME(schema_id) AS SchemaName,
OBJECT_NAME(o.object_id) AS ObjectName,
type AS ObjectType,
s.name AS StatsName,
STATS_DATE(o.object_id, stats_id) AS StatsDate
FROM sys.stats s
INNER JOIN sys.objects o ON o.object_id=s.object_id
WHERE OBJECTPROPERTY(o.object_id, N'ISMSShipped') = 0
AND LEFT(s.Name, 4) != '_WA_'
@veysby
veysby / gist:fdeac9145d11f82a093d
Created January 27, 2015 16:43
MSSQL: index fragmentation
SELECT
OBJECT_NAME(ind.OBJECT_ID) AS TableName,
ind.name AS IndexName,
indexstats.index_type_desc AS IndexType,
indexstats.avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, NULL) indexstats
INNER JOIN sys.indexes ind ON ind.object_id = indexstats.object_id AND ind.index_id = indexstats.index_id
WHERE indexstats.avg_fragmentation_in_percent > 30--You can specify the percent as you want
ORDER BY
indexstats.avg_fragmentation_in_percent DESC
@veysby
veysby / gist:ba81e5c9eafbd3efc052
Created January 27, 2015 17:06
MSSQL: list tables, indexes, indexed columns, etc
--Source: http://simplesqlserver.com/2013/11/20/indexing-fundamentals/
DECLARE @TableName VarChar(100)
SELECT @TableName = '%'
SELECT TableName = i.SchemaName + '.' + i.TableName
, IndexName = ISNULL(i.IndexName, '[' + Lower(i.IndexType) + ']')
--, SeekUpdateRatio = CASE WHEN i.User_Updates > 0 THEN CAST(i.User_Seeks / CAST(i.User_Updates as DEC(20,1)) as DEC(20,2)) ELSE 0 END
, i.User_Updates
, i.User_Seeks
@veysby
veysby / gist:9586722a06add9b9548a
Created March 3, 2015 16:57
MSSQL: cached query plans
-- DO NOT RUN this script on Production environment
-- Clear the plan cache
dbcc freeproccache
-- Look at the cached query plans
select st.text,*
from sys.dm_exec_cached_plans cp
cross apply sys.dm_exec_sql_text(cp.plan_handle) st
where (st.text like '%select * from Person.Address%')
and st.text not like '%select st.text%'
@veysby
veysby / MSSQL_test_table.sql
Last active December 10, 2015 16:17
MSSQL: Create test table with random data
SELECT TOP 1000000
IDENTITY(INT,1,1) AS UniqueInt,
CAST(NEWID() AS VARCHAR(36)) AS UniqueVarChar
INTO #TestTable
FROM Master.sys.All_Columns ac1
CROSS JOIN Master.sys.All_Columns ac2
@veysby
veysby / Vagrantfile
Last active December 10, 2015 16:33
Vagrant: 3 machines in private network
Vagrant.configure("2") do |config|
config.vm.define "lb" do |lb|
lb.vm.box = "centos65"
lb.vm.host_name = "lb"
lb.vm.network "private_network", ip: "192.168.0.20"
lb.vm.network :forwarded_port, guest: 22, host: 2220, id: "ssh", auto_correct: true
lb.vm.network :forwarded_port, guest: 80, host: 9099, id: "web", auto_correct: true
config.vm.provider :virtualbox do |vb|