rs_truncate

Description

Truncates a table or a table partition in a replicate database.

Examples

Example 1

Replaces the existing rs_truncate function string for the authors table with one that executes a Transact-SQL delete command, which logs all deletions, instead of the truncate table command, which does not log deletions.

alter function string authors.rs_truncate
 for sqlserver_derived_class
 output language
 'delete authors'

You would want to customize the rs_truncate function string for the authors table, if:

Example 2

Replaces the existing rs_truncate function string for the publisher table to replicate truncate table partition as a delete command:

alter function string publisher.rs_truncate
  for rs_sqlserver_function_class
  output language
  'begin transaction
    if (?1!param? = '''') /* No parameter */
      delete publisher
    if (?1!param? = ''A'')
      delete publisher where c1 < 1000
    if (?1!param? = ''B'')
      delete publisher where c1 >= 1000
commit transaction'

Example 3

Alters the function string to do nothing if there is a parameter so that table partitions are not truncated at replicate:

alter function string publisher.rs_truncate
  for rs_sqlserver_function_class
  output language
  'if(?1!param? = '''') delete publisher'

Usage

See also

alter function string, rs_datarow_for_writetext, rs_get_textptr, rs_insert, rs_delete, rs_textptr_init, rs_writetext, set