Question:

Copy Database Structure in SQL not Records

by Guest65604  |  earlier

0 LIKES UnLike

Hi, I want to copy Database structure in SQL, not records, for using the same data as a new copy for another system

 Tags:

   Report

2 ANSWERS


  1. SQL> create table sample(id integer primary key, name varchar2(10));

    Table created.

    SQL> insert into sample values(&id, '&name');

    Enter value for id: 1

    Enter value for name: kishore

    old   1: insert into sample values(&id, '&name')

    new   1: insert into sample values(1, 'kishore')

    1 row created.

    SQL> /

    Enter value for id: 2

    Enter value for name: kali

    old   1: insert into sample values(&id, '&name')

    new   1: insert into sample values(2, 'kali')

    1 row created.

    SQL> select * from sample;

            ID NAME

    ---------- ----------

             1 kishore

             2 kali

    SQL> commit

      2  ;

    Commit complete.

    SQL> create table sam as (select * from sample);

    Table created.

    SQL> select * from sam;

            ID NAME

    ---------- ----------

             1 kishore

             2 kali

    SQL> desc sample;

    Name                                      Null?    Type

    ----------------------------------------... -------- ----------------------------

    ID                                                 NUMBER(38)

    NAME                                           VARCHAR2(10)

    SQL> create table sample1 as (select * from sample where id='');

    Table created.

    SQL> select * from sample1;

    no rows selected

    SQL> desc sample1;

    Name                                      Null?    Type

    ----------------------------------------... -------- ----------------------------

    ID                                                 NUMBER(38)

    NAME                                           VARCHAR2(10)

    I have created another table from existing table with a condition that will never be true so that i will get only the structure of the table;

    Say that you dont want any condion to be specified then you can just create a copy of the table with all the colums then delete or truncate the data.


  2. Using the Enterprise Manager (or SQL Server Manager if you're using Express), select the DB, and Export to file. You should be given the choice to include data.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.