Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7515421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:48:08+00:00 2026-05-30T00:48:08+00:00

I am working on a request where I have to create a table to

  • 0

I am working on a request where I have to create a table to insert some data. So, obviously I will have first have a delete table st. before the create st. but when I am running this for the first time(before the table can be created) it will pop up an error saying table not created and then creates table and goe son from here. So every time any one runs my code for the first time it will pop up this error at drop table st. Does any one have any better idea??

Some thing like ” if table exists then drop else create table”
I am not sure how are we going to do this in sql

Drop table table_name;————–> here it throws an error for the first time saying table does not exist.

Create table table_name

{ so on };

By the way I am working on Teradata but a simple sql logic would help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T00:48:10+00:00Added an answer on May 30, 2026 at 12:48 am

    You can create a stored procedure owned by SYSDBA or other admin level user with adequate DROP TABLE and CREATE TABLE privileges that does the following:

    1. Check DBC.Tables to see if object exists.
    2. If object exists, drop it.
    3. Run the DDL to recreate the table: CREATE TABLE <TargetDB>.<TargetTable> AS <SourceDB>.<SourceTable> WITH DATA AND STATS;

    You can make it more dynamic by accepting additional parameters on whether the data and/or stats should be copied to the new table.

    If you are using BTEQ, you can do something similar (BTEQ command syntax may be a little off but close enough to get the point across):

    SELECT 1 
    FROM DBC.TABLES 
    WHERE DatabaseName = '<TargetDB>'
      AND TableName = '<TargetTable>'
      AND TableKind = 'T' /* Make sure it is in fact a table, not a view, macro etc */
    
    
    .IF ACIVITYCOUNT = 0 THEN GOTO CreateNewTable;
    
    DROP TABLE <TargetDB>.<TargetTable>;
    
    .IF ERRORCODE = 3807 THEN GOTO CreateNewTable; /* Table dropped by another process? */
    .IF ERRORCODE > 0 THEN .QUIT ERRORCODE; /* Unexpected error */
    
    .LABEL CreateNewTable;
    
    CREATE <TargetDB>.<TargetTable> AS <SourceDB>.<SourceTable> WITH DATA AND STATISTICS;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code working in C#: var request = (HttpWebRequest)WebRequest.Create(https://x.com/service); request.Method = GET;
I'm working on a request timeout mechanism. My initial approach would be to create
I have a project that I have recently started working on seriously but had
I would like to create user in my user table when new user have
I'm currently working on creating electronic version of various request forms. Each form will
I have been working on a project recently where a Player can create a
I'm working on a web project, which have to process so many client requests.
I’m trying to issue web requests asynchronously. I have my code working fine except
I'm working out the reasonability of a request to keep all documents with executable
I am working with a loader to request an image from a WMS(Web Mapping

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.