Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 
);
like image 465
vashishth Avatar asked Oct 08 '13 05:10

vashishth


People also ask

Can I create multiple table in SQL?

Using the "CREATE SCHEMA" command you can combine multiple DDL steps into a single statement. As a result, the failure of a single part causes all commands within the "CREATE SCHEMA" to be rolled back. CREATE SCHEMA is limited to creating tables, views and issuing grants.

Can we create multiple tables in a single database?

You can create several tables and views and grant privileges in one operation using the CREATE SCHEMA statement. If an individual table, view or grant fails, the entire statement is rolled back. None of the objects are created, nor are the privileges granted.

Can I insert into 2 tables at once SQL?

The T-SQL function OUTPUT, which was introduced in 2005, can be used to insert multiple values into multiple tables in a single statement. The output values of each row that was part of an INSERT, UPDATE or DELETE operation are returned by the OUTPUT clause.


1 Answers

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 );
like image 60
Dba Avatar answered Sep 19 '22 08:09

Dba