How to create a temporaray table every time when the procedure is called.

Posted on 2012-09-21
Last Modified: 2012-09-22
The procedure should check whether the table is existing, if it exists it should
How to create a temporary table every time when the procedure is called,
The table should get deleted first and then recreated every time
Question by:searchsanjaysharma
    LVL 11

    Accepted Solution

    if object_id (N'tempdb..#tablename', N'U') is not null
                drop table #tablename;

    create #tablename ()
    LVL 19

    Assisted Solution

    by:Bhavesh Shah

    you no need to explicitly drop the temporary table in procedure.
    temp Table itself get dropped after completion of execution of procedure.

    Author Closing Comment


    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
    In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now