DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2000
    I want to create a new table with all the data from an existing table. I understand that I can use
    create table new_table_name
    select * from old_table

    But I want to check whether there is any row in the old_table first. Can this be done in sql? Thanks, Rong

  2. #2
    Join Date
    May 2000
    Portsmouth, NH, USA

    Thumbs up yes

    looks good.

    to check if data exists in Table_1 just use:
    select count(*) from Table_1;

    if you get at least an output of "1" then there is at least one row in the table.

    then just use the:
    create table Table_2
    AS select *
    from Table_1;

  3. #3
    Join Date
    May 2000
    Richardson, Texas, USA
    Just a tip:

    I case the table contains too many rows the following
    will save some time:

    select count(*) from Table_1 where rownum=1;

    If it returns 1 then the table has row(s) inside it, if 0 then it's empty. It'll run really fast since it checks only the first row.



Posting Permissions

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

Click Here to Expand Forum to Full Width

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.