Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2011
    Posts
    10

    Unanswered: Help needed : Truncating a table based on a condition

    Dear Friends,

    I am writing a script and want to execute from the OS level. I have one doubt, How do I truncate the table based on some condition. Here let us assume that I want to truncate the whole table if the count(*) reaches 200,000. Please provide syntaxes for the same.

  2. #2
    Join Date
    Aug 2011
    Posts
    10

    Pls reply

    Please reply .. :'( im eagerly waiting.

  3. #3
    Join Date
    May 2011
    Posts
    28

    Help needed : Truncating a table based on a condition

    Hi,
    Following syntax can be used.

    Code:
    if exists(select 1 from T1 having count(1)>200000 )
    begin
    	exec ('truncate table T1')
    end
    go
    OR

    Code:
    if (select count(*) from T1) >200000
    begin
    	exec ('truncate table T1')
    end
    go

  4. #4
    Join Date
    Aug 2011
    Posts
    10

    Thank you

    Thank you very much friend.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •