Skip to content

Instantly share code, notes, and snippets.

View bvanskiver's full-sized avatar

Bernd VanSkiver bvanskiver

View GitHub Profile
@bvanskiver
bvanskiver / runscripts.bat
Last active August 29, 2015 14:13
Run all SQL scripts in folder
for /R "C:\Database\Stored Procedures" %i in (*.sql) do sqlcmd -S -T . -d DatabaseName -i "%~fi"
@bvanskiver
bvanskiver / killprocesses.sql
Created January 19, 2015 12:51
Kill all processes in specified database(s)
declare @spid int, @cnt int, @sql varchar(255)
select @spid = min(spid), @cnt = COUNT(*)
from sysprocesses p
inner join sysdatabases d on p.[dbid] = d.[dbid]
where d.name like '%Internal%'
print 'Killing ' + CAST(@cnt as varchar) + ' processes.'
while @spid is not null
@bvanskiver
bvanskiver / disablefks.sql
Created January 19, 2015 12:53
Disable all foreign key constraints
-- Disables all FK constraints
exec sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT all'
-- Enables all FK constraints
exec sp_msforeachtable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all'
@bvanskiver
bvanskiver / db_executor-role.sql
Created February 7, 2015 23:18
db_executor role
-- Create role and grant permissions
create role db_executor
grant execute to db_executor
-- Add user(s) to role
exec sp_addrolemember 'db_executor', 'username'
@bvanskiver
bvanskiver / killdbusers.sql
Created January 28, 2016 15:45
Kill all users in specified database(s)
declare @spid int, @cnt int, @sql varchar(255)
select @spid = min(spid), @cnt = COUNT(*)
from sysprocesses p
inner join sysdatabases d on p.[dbid] = d.[dbid]
where d.name like '%Internal%'
print 'Killing ' + CAST(@cnt as varchar) + ' processes.'
while @spid is not null
@bvanskiver
bvanskiver / dbsearch.sql
Created January 28, 2016 15:45
Searching in objects
select distinct name
from sysobjects o
inner join syscomments c on o.id = c.id
where text like '%OrganizationID%'
@bvanskiver
bvanskiver / spaceused.sql
Last active January 23, 2023 12:15
Space used by tables
declare @SpaceUsed table (TableName sysname, NumRows bigint, ReservedSpace varchar(50), DataSpace varchar(50), IndexSize varchar(50), UnusedSpace varchar(50))
declare @str varchar(500)
set @str = 'exec sp_spaceused ''?'''
insert into @SpaceUsed
exec sp_msforeachtable @command1=@str
select TableName,
FORMAT(CAST(NumRows as bigint), 'N0') as NumRows,
FORMAT(CAST(REPLACE(ReservedSpace, ' KB', '') as bigint), 'N0') + ' KB' as ReservedSpace,
@bvanskiver
bvanskiver / connectionstrings.config
Created April 4, 2016 16:10
Connection Strings
Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;
REM Package folder named .\1001\ in to zip file, use the * at the end to keep from creating a base folder in the zip file.
"C:\Program Files\7-Zip\7z.exe" a -tzip 1001.zip .\1001\*
REM Build single zip file for each folder in current directory.
for /D %d in (*) do "C:\Program Files\7-Zip\7z.exe" a "%d.zip" ".\%d\*"
REM Build single zip file for each folder in current directory and keep folder in root.
for /D %d in (*) do "C:\Program Files\7-Zip\7z.exe" a "%d.zip" ".\%d\"
@bvanskiver
bvanskiver / shrew-soft-shortcut.bat
Last active March 14, 2023 07:25
Shrew Soft VPN client shortcut with saved credentials
rem http://www.shrew.net/
"C:\Program Files\ShrewSoft\VPN Client\ipsecc.exe" -r "VPN Profile Name" -u "Username" -p "Password" -a