table name as parameter

Last post 08-19-2008 4:37 AM by Madhivanan. 5 replies.
Page 1 of 1 (6 items)
Active Topics My Discussions Unanswered Sort Posts: Previous Next
  • 08-18-2008 11:27 AM

    • v1rt
    • Not Ranked
    • Joined on 05-07-2008
    • Posts 8

    table name as parameter

    Hi folk,

    I would like to make a stored procedure for truncating tables. However, I would like to add the table name as one of the parameters. How do I do that?

    Thanks.

    V1rt

  • 08-18-2008 12:17 PM In reply to

    • preethi
    • Top 100 Contributor
    • Joined on 07-01-2003
    • Sri Lanka
    • Posts 169

    Re: table name as parameter

    Warning 1:You are trying something extremely dangerous. Truncating table will distroy all data. There is no way of recovering other than restoring from a backup/database snapshot. It will simply remove the links between table header and data pages.
    Warning 2: TRUNCATE TABLE will not work if the table is referenced by another table. (even if the other tabel is empty)
    You may have to think of DELETE without where clause to do the same to tables where referential integrity is maintainied
    Now, Let me coem tot he answer: Use dynamic SQL.
    Warning 3:This is another dangerous command. unless you validate the data fully, Others can use SQL injection method and destroy your entire database.

    Cheers,
    Preethiviraj Kulasingham
    MCITP:DBA
  • 08-18-2008 12:22 PM In reply to

    • v1rt
    • Not Ranked
    • Joined on 05-07-2008
    • Posts 8

    Re: table name as parameter

    Thank you so much. I'm not worried since it is not going to be used by a web based application. We only have 6 users and the app is a stand alone.

    So if dynamic SQL, can you please share to me how the sql code would be? And yes, I am aware of what TRUNCATE data does.

    Thanks,

    V1rt

  • 08-18-2008 12:25 PM In reply to

    • v1rt
    • Not Ranked
    • Joined on 05-07-2008
    • Posts 8

    Re: table name as parameter

    Disregard my last post, I found a code. :)

  • 08-19-2008 4:36 AM In reply to

    Re: table name as parameter

    preethi:

    Warning 1:You are trying something extremely dangerous. Truncating table will distroy all data. There is no way of recovering other than restoring from a backup/database snapshot. It will simply remove the links between table header and data pages.
    Warning 2: TRUNCATE TABLE will not work if the table is referenced by another table. (even if the other tabel is empty)
    You may have to think of DELETE without where clause to do the same to tables where referential integrity is maintainied
    Now, Let me coem tot he answer: Use dynamic SQL.
    Warning 3:This is another dangerous command. unless you validate the data fully, Others can use SQL injection method and destroy your entire database.

    1 Truncate can be rollbacked within a single scope

    Madhivanan

    Failing to plan is Planning to fail
  • 08-19-2008 4:37 AM In reply to

    Re: table name as parameter

    v1rt:

    Disregard my last post, I found a code. :)

    Make sure you read this
    www.sommaarskog.se/dynamic_sql.html

    Madhivanan

    Failing to plan is Planning to fail
Page 1 of 1 (6 items)
Active Topics   My Discussions    Unanswered Posts


© 2000 - 2007 vDerivatives Limited All Rights Reserved.