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
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 *
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.
Click Here to Expand Forum to Full Width