Sergio Tapia
Sergio Tapia

Reputation: 41188

How can I create a sequential SQL creation script for Oracle?

Something like:

create table Employee(
ID int primary key,
Name nvarchar(200)
IDArea int foreign key references Area(ID)
);

go

create table Area(
ID int primary key,
Name nvarchar(200)
);

Does something like this exist in Oracle?

Upvotes: 2

Views: 314

Answers (2)

Tony Andrews
Tony Andrews

Reputation: 132650

Yes, just leave out the "GO" keywords and put the statements in a file:

create table Area(
ID int primary key,
Name nvarchar2(200)
);

create table Employee(
ID int primary key,
Name nvarchar2(200),
IDArea int references Area(ID)
);

You must create the Area primary key before the foreign key that references it, so I have swapped these around. Also the foreign key syntax is slightly different in Oracle.

Upvotes: 2

N. Gasparotto
N. Gasparotto

Reputation: 1089

You should first create the master table, forget nvarchar datatype, and eventually the script would be :

create table Area( 
ID number primary key, 
Name varchar2(200) 
); 

create table Employee( 
ID number primary key, 
Name varchar2(200) ,
IDArea number, constraint fk_idarea foreign key (idarea) references Area(ID) 
); 

Upvotes: 1

Related Questions