Search code examples
sqldatabaseoracle-databaseoracle11goracle-sqldeveloper

Create multiple tables using single .sql script file


I have created multiple table in oracle xe 11g database and i have saved the script for each table in different .sql file. But i need to create all tables at once using single .sql file. I tried to run below script but it is creating only once table at once.

CREATE TABLE ACCOUNT_DETAILS_TB 
(
  CUSTOMER_ID VARCHAR2(20) NOT NULL 
, ACCOUNT_ID VARCHAR2(20) NOT NULL 
);

CREATE TABLE ADDRESS_DETAILS_TB 
(
  ACCOUNT_ID VARCHAR2(20) NOT NULL 
, ADDRESS_ID VARCHAR2(20) NOT NULL 
);

Solution

  • You need to separate the create table scripts with / or end the command with ;, Try like this,

    CREATE TABLE ACCOUNT_DETAILS_TB ( CUSTOMER_ID VARCHAR2(20) NOT NULL , ACCOUNT_ID VARCHAR2(20) NOT NULL )
    /
    CREATE TABLE ADDRESS_DETAILS_TB ( ACCOUNT_ID VARCHAR2(20) NOT NULL , ADDRESS_ID VARCHAR2(20) NOT NULL )
    /
    

    OR

    CREATE TABLE ACCOUNT_DETAILS_TB ( CUSTOMER_ID VARCHAR2(20) NOT NULL , ACCOUNT_ID VARCHAR2(20) NOT NULL );
    
    CREATE TABLE ADDRESS_DETAILS_TB ( ACCOUNT_ID VARCHAR2(20) NOT NULL , ADDRESS_ID VARCHAR2(20) NOT NULL );