|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, March 30, 2011 1:00 AM
Points: 14,
Visits: 17
|
|
/*I Do It As Follows:*/ DECLARE @ROWCOUNT INT DECLARE @sSQL NVARCHAR(2000) CREATE TABLE #DropTableNames( TableName VARCHAR(30), TableID INT IDENTITY(1,1) not null) INSERT INTO #DropTableNames(TableName) SELECT Table_Name FROM INFORMATION_SCHEMA.TABLES WHERE Table_Type='BASE TABLE' SET @ROWCOUNT=@@ROWCOUNT WHILE @ROWCOUNT>0 BEGIN SELECT @sSQL='TRUNCATE TABLE '+TableName FROM #DropTableNames WHERE TableID=@ROWCOUNT SET @ROWCOUNT=@ROWCOUNT-1 EXEC SP_EXECUTESQL @sSQL END /*My English is poor So ...Here Is No Marker*/
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 8:55 AM
Points: 137,
Visits: 250
|
|
If not references are present on the tables: EXEC sp_MSForEachTable 'truncate TABLE ? ' will be enough to truncate all tables. the sp_MSForEachTable replace the ? for the actual table Name.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 8:55 AM
Points: 137,
Visits: 250
|
|
You can join the table with the names of tables also the statement.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Wednesday, September 12, 2012 5:17 AM
Points: 329,
Visits: 461
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 8:55 AM
Points: 137,
Visits: 250
|
|
| Very good information on the link. Like the Blog stated there are many ways to aproach and problem..Thanks for the input.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, October 28, 2010 6:57 AM
Points: 1,
Visits: 0
|
|
i am vipul and i use this method to truncate all table from database. but constraint was not enabling by
Exec sp_MSforeachtable 'alter table ? check constraint all' print 'all constraint enable'
MESSAGE WILL APPEAR THAT- 'all constraint enable'
BUT WHEN I CHECK THE DATABASE ALL CONSTRAINT DISABLE
SO WHAT I SHOULD DO ENABLE AGAIN ALL THE CONSTRAINT
VIPUL SACHAN
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 10:01 PM
Points: 2,944,
Visits: 10,504
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, February 20, 2013 4:14 AM
Points: 198,
Visits: 588
|
|
| Just a thought, but if TRUNCATE then likely will reset SEEDS and there might be some cases where these might need to be kept? Maybe. Possibly. Especially if fed through to another system or report? Maybe.
|
|
|
|