SQL-SERVER Concepts

Return all the tables in the database which user have created

USE YourDataBaseName
GO

SELECT *
FROM sys.Tables
GO

To get all the databases on a server, you can use the same technique, but just a bit different query.

USE Master
GO

SELECT *
FROM sys.Databases
GO

For a list of all tables on a server

sp_msforeachdb @command1='USE ?;SELECT * FROM sys.Tables'

Reset Identity Column Value in SQL Server

If you are using an identity column on your SQL Server tables, you can set the next insert value to whatever value you want. An example is if you wanted to start numbering your ID column at 1000 instead of 1.

First check what the current identify value is. We can use this command to do so:
DBCC CHECKIDENT (’tablename’, NORESEED)

For instance, if I want to check the next ID value of my orders table, I could use this command:
DBCC CHECKIDENT (orders, NORESEED)

To set the value of the next ID to be 1000, I can use this command:
DBCC CHECKIDENT (orders, RESEED, 999)

Note that the next value will be whatever you reseed with + 1, so in this case I set it to 999 so that the next value will be 1000.

Another thing to note is that you may need to enclose the table name in single quotes or square brackets if you are referencing by a full path, or if your table name has spaces in it.
DBCC CHECKIDENT ( ‘databasename.dbo.orders’,RESEED, 999)

Get all Open Transactions in SQL

How to check what is in SQL server plan cache


No comments :