Skip to content

Instantly share code, notes, and snippets.

@shbaz
shbaz / gist:1196551
Created September 6, 2011 04:04 — forked from zommarin/gist:1195238
git snippets
#
# Misc good to have commands when using git
#
# Short and nice log
git log --pretty=oneline Path
# Create a new freestanding branch
git symbolic-ref HEAD refs/heads/<branch-name>
rm .git/index -ErrorAction SilentlyContinue
@shbaz
shbaz / gist:1188369
Created September 2, 2011 10:48
git snippets
#
# Misc good to have commands when using git
#
# Short and nice log
git log --pretty=oneline Path
# Create a new freestanding branch
git symbolic-ref HEAD refs/heads/<branch-name>
rm .git/index -ErrorAction SilentlyContinue
@shbaz
shbaz / gist:1188041
Created September 2, 2011 06:36
All objects not in dbo or sys schema
SELECT s.name, o.name, o.type, o.type_desc, s.schema_id
FROM sys.objects AS o
INNER JOIN sys.schemas AS s ON o.schema_id = s.schema_id
WHERE s.name NOT IN ( 'dbo', 'sys' )
@shbaz
shbaz / gist:1188035
Created September 2, 2011 06:31
Remove all non-dbo schemas, views and stored procedures
--
-- Remove non dbo tables, views and stored procedures
--
BEGIN TRANSACTION
DECLARE @Cmd NVARCHAR(max);
DECLARE [CmdCursor] CURSOR FAST_FORWARD READ_ONLY FOR
SELECT 'DROP TABLE [' + s.name + '].[' + t.name + '];'
@shbaz
shbaz / gist:1188016
Created September 2, 2011 06:17
Find non-dbo tables, views and procedures [SQL Server]
--
-- Select the tables, views and stored procedures that are not in the [dbo] schema
--
-- Useful when double checking that prople has not run scripts with the wrong user
-- for databases that have everything in the [dbo] schema.
--
SELECT 'Table' AS [Type] ,
'[' + s.name + '].[' + t.name + ']' AS [Name]
FROM sys.tables AS t
@shbaz
shbaz / gist:1188006
Created September 2, 2011 06:05
Size of tables in a SQL Server database
--
-- Count rows in all tables, display tables with rows
--
CREATE TABLE #T (
name NVARCHAR(255),
[rows] INT,
reserved NVARCHAR(255),
data NVARCHAR(255),
index_size NVARCHAR(255),