Skip to content

Instantly share code, notes, and snippets.

@malbarmavi
Last active February 15, 2024 17:16
Show Gist options
  • Save malbarmavi/d2722bedc2f02ea2e4e62a6cd3f97c5b to your computer and use it in GitHub Desktop.
Save malbarmavi/d2722bedc2f02ea2e4e62a6cd3f97c5b to your computer and use it in GitHub Desktop.
MS SQL Server Most Useful Queries
select * from master.dbo.sysdatabases;
use DataBaseName;
select * from information_schema.tables;
select TABLE_NAME 'Table Name',COUNT(COLUMN_NAME) 'Column Count'
from information_schema.COLUMNS group by TABLE_NAME order by [TABLE_NAME];
select @@CONNECTIONS;
select @@SERVERNAME;
select @@SERVICENAME;
select @@VERSION;
--http://stackoverflow.com/questions/42648/best-way-to-get-identity-of-inserted-row
select @@IDENTITY;
select SCOPE_IDENTITY();
select IDENT_CURRENT('tableName') ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment