Showing posts with label given. Show all posts
Showing posts with label given. Show all posts

Friday, November 4, 2016

Simplest way to Truncate/Delete all tables in a given database.


Simplest way to Truncate all tables in a given database.
Use databasename
EXEC sp_MSForEachTable 'Truncate TABLE ?' --- For Truncating all tables



Simplest way to Truncate all tables in a given database.
Use databasename
EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"  --- For Deleting all tables

Tuesday, September 23, 2014

Script to split given range of values in to desired number of parts in SQL Server

DECLARE @min NUMERIC(18, 0)
DECLARE @max NUMERIC(18, 0)
DECLARE @parts NUMERIC(18, 0)

SELECT @min = 102201011472463
 ,-- Minimum value in your range of values
 @max = 102201354392808
 ,-- Maximum value in your range of values
 @parts = 3480 --Give number of parts

DECLARE @increment INT = (@max - @min) / @parts

WHILE @max >= @min
BEGIN
 DECLARE @newMin NUMERIC(18, 0) = @min + @increment

 PRINT convert(VARCHAR, @min) + ' - ' + convert(VARCHAR, @newMin)

 SELECT @min = @newMin + 1
END