Created
August 14, 2019 22:31
-
-
Save karoltheguy/ffe0164b4afa5d66b0b96ced21590677 to your computer and use it in GitHub Desktop.
SQLCMD bits
This file contains hidden or 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
| #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