-- Create
a new database
CREATE DATABASE AnotherDB;
-- Modify
the database name
ALTER DATABASE AnotherDB MODIFY NAME = MyCustomDB;
-- Rename
the database using sp_rename
EXEC sp_rename 'MyCustomDB', 'MyFinalDB';
-- Drop
the database
DROP DATABASE MyFinalDB;
-- Enable
explicit values to be inserted into the identity column of NewTable
SET IDENTITY_INSERT NewTable ON;
-- Insert
specific values into NewTable
INSERT INTO NewTable (ID, Name, Email) VALUES (1, 'Hi', 'Hi@example.com');
--
Disable explicit values insertion
SET IDENTITY_INSERT NewTable OFF;
-- Reseed
the identity column to 0
DBCC CHECKIDENT('NewTable', RESEED, 0);
-- Take
the database offline
ALTER DATABASE DatabaseName SET OFFLINE WITH ROLLBACK IMMEDIATE;
-- Modify
the database name
ALTER DATABASE DatabaseName MODIFY NAME = NewDatabaseName;
-- Bring
the database back online
ALTER DATABASE NewDatabaseName SET ONLINE;
-- Ensure
you are in the master database
USE master;
-- Rename
the database
EXEC sp_rename 'OldDatabaseName', 'NewDatabaseName';
--
Retrieve the last identity value in the current scope
SELECT SCOPE_IDENTITY();
--
Retrieve the last identity value, not limited to the current scope
SELECT @@IDENTITY;
--
Retrieve the last identity value for a specific table
SELECT IDENT_CURRENT('YourTableName');