Skip to content

Instantly share code, notes, and snippets.

@karoltheguy
Created August 14, 2019 22:31
Show Gist options
  • Select an option

  • Save karoltheguy/ffe0164b4afa5d66b0b96ced21590677 to your computer and use it in GitHub Desktop.

Select an option

Save karoltheguy/ffe0164b4afa5d66b0b96ced21590677 to your computer and use it in GitHub Desktop.
SQLCMD bits
#LIST DBS#
SELECT name FROM master.sys.databases
#CONNECT TO MSSQL#
sqlcmd -S localhost\SQLEXPRESS -E
#USE DB#
use SQLEXPRESS
#GET COLUMN NAMES OF A TABLE#
SELECT
COLUMN_NAME
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'BPASessionLog_NonUnicode'
# SELECT ALL COLUMNS TO VIEW DATA#
select * from SQLEXPRESS.dbo.BPASessionLog_NonUnicode
# REMOVE ROWS THAT ARE OLDER THAN 15 DAYS#
Delete FROM dbo.BPASessionLog_NonUnicode WHERE startdatetime < DATEADD(day, -15, GETDATE())
#GET THE AMOUNT OF SPACE USED BY A TABLE#
exec sp_spaceused N'dbo.BPASessionLog_NonUnicode'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment