Sie sind auf Seite 1von 4

/*****creacion del usuario ******/

create user northwind identified by northwind;


grant all privileges to northwind;
/*****creacion de tablas ********/
Create Table Categories
(
CategoryId Number Not Null,
CategoryName VarChar2(15) Not Null,
Description VarChar2(100) Null,
Picture VarChar2(100) Null,
Constraint Pk_Categories_CategoryId
Primary Key (CategoryId)
);
Create Table Shippers
(
ShipperId Number Not Null,
CompanyName VarChar2(40) Not Null,
Phone VarChar2(24) Null,
Constraint Pk_Shippers_ShipperId
Primary Key (ShipperId)
);
Create Table Suppliers
(
SupplierId Number Not Null,
CompanyName VarChar2(40) Not Null,
ContactName Varchar2(30) Not Null,
ContactTitle VarChar2(30) Not Null,
Address VarChar2(80) Not Null,
City VarChar2(15) Null,
Region VarChar2(15) Null,
PostalCode VarChar2(10) Null,
Country VarChar2(15) Null,
Phone VarChar2(24) Null,
Fax VarChar2(24) Null,
HomePage VarChar2(100) Null,
Constraint Pk_Suppliers_SupplierId
Primary Key (SupplierId)
);
Create Table CustomerDemographics
(
CustomerTypeId Char(10) Not Null,
CustomerDesc VarChar2(100) Null,
Constraint Pk_CustD_CustomerTypeId
Primary Key (CustomerTypeId)
);
Create Table Region
(
RegionId Number Not Null,
RegionDescription VarChar2(100) Null,
Constraint Pk_Region_RegionId
Primary Key (RegionId)
);
Create Table Products
(
ProductId Number Not Null,
ProductName VarChar2(40) Not Null,
SupplierId Number Not Null,
CategoryId Number Not Null,
QuantityPerUnit VarChar2(20) Not Null,
UnitPrice Number(6,2) Not Null,
UnitsInStock Number Null,
UnitsInOrder Number Null,
ReorderLevel Number Null,
Discontinued Number Default 0 Not Null,
Constraint Pk_Products_ProductId
Primary Key (ProductId),
Constraint Chk_Products_Discontinued
Check ((Discontinued = 1) or (Discontinued = 0)) ,
Constraint Fk_Products_Suppliers
Foreign Key (SupplierId) References Suppliers(SupplierId) on Delete Casc
ade,
Constraint Fk_Products_Categories
Foreign Key (CategoryId) References Categories(CategoryId) on Delete Cas
cade
);
Create Table CustomerCustomerDemo
(
CustomerId Char(5) Not Null,
CustomerTypeId Char(5) Not Null,
Constraint Pk_CCDemo
Primary Key (CustomerId),
Constraint Fk_CCDemo_CustD
Foreign Key (CustomerTypeId) References CustomerDemographics(CustomerTyp
eId) on Delete Cascade
);
Create Table Customers
(
CustomerId Char(5) Not Null,
CompanyName VarChar2(40) Not Null,
ContactName VarChar2(30) Not Null,
ContactTitle VarChar2(30) Null,
Address VarChar2(60) Null,
City VarChar2(15) Null,
Region VarChar2(15) Null,
PostalCode VarChar2(10) Null,
Country VarChar2(15) Null,
Phone VarChar2(24) Null,
Fax VarChar2(24) Null,
Constraint Pk_Customers_CustomerId
Primary Key (CustomerId),
Constraint Fk_Customers_CCDemo
Foreign Key (CustomerId) References CustomerCustomerDemo(CustomerId) on
Delete Cascade
);
Create Table Territories
(
TerritoryId VarChar2(20) Not Null,
TerritoryDescription VarChar2(50) Null,
RegionId Number Null,
Constraint Pk_Territories_TerritoryId
Primary key (TerritoryId),
Constraint Fk_Territories_Region
Foreign Key (RegionId) References Region(RegionId) on Delete Cascade
);
Create Table Employees
(
EmployeeId Number Not Null,
LastName VarChar2(20) Not Null,
FirstName VarChar2(10) Not Null,
Title VarChar2(30) Not Null,
TitleOfCourtesy VarChar2(25) Null,
BirthDate Date Null,
HireDate Date Null,
Address VarChar2(60) Null,
City VarChar2(15) Null,
Region VarChar2(15) Null,
PostalCode VarChar2(10) Null,
Country VarChar2(15) Null,
HomePhone VarChar2(24) Null,
Extension VarChar2(4) Null,
Photo VarChar2(100) Null,
Notes VarChar2(100) Null,
ReportsTo Number Null,
PhotoPath VarChar2(255) Null,
Constraint Pk_Employees_EmployeeId
Primary Key (EmployeeId),
Constraint Fk_Employees_Employees
Foreign Key (ReportsTo) References Employees(EmployeeId)
);
Create Table EmployeeTerritories
(
EmployeeId Number Null,
TerritoryId VarChar2(20) Null,
Constraint Pk_EmpTerr_EmpIdTerrId
Primary Key (EmployeeId,TerritoryId),
Constraint Fk_EmpTerr_Territories
Foreign Key (TerritoryId) References Territories(TerritoryId) on Delete
Cascade,
Constraint Fk_EmpTerr_Employees
Foreign Key (EmployeeId) References Employees(EmployeeId) on Delete Casc
ade
);
Create Table Orders
(
OrderId Number Not Null,
CustomerId Char(5) Not Null,
EmployeeId Number Not Null,
OrderDate Date Null,
RequiredDate Date Null,
ShippedDate Date Null,
ShipVia Number Null,
Freight Number(6,2) Null,
ShipName VarChar2(40) Null,
ShipAddress VarChar2(60) Null,
ShipCity VarChar2(15) Null,
ShipRegion VarChar2(15) Null,
ShipPostalCode VarChar2(10) Null,
ShipCountry VarChar2(15) Null,
Constraint Pk_Orders_OrderId
Primary Key (OrderId),
Constraint Fk_Orders_Customers
Foreign Key (CustomerId) References Customers(CustomerId),
Constraint Fk_Orders_Employees
Foreign Key (EmployeeId) References Employees(EmployeeId),
Constraint Fk_Orders_Shippers
Foreign Key (ShipVia) References Shippers(ShipperId)
);
Create Table Order_Details
(
OrderId Number Not Null,
ProductId Number Not Null,
UnitPrice Number(6,2) Null,
Quantity Number Null,
Discount Number(4,2) null,
Constraint Pk_OrderDetails
Primary Key (OrderId,ProductId),
Constraint Fk_OrderDetails_Orders
Foreign Key (OrderId) References Orders(OrderId),
Constraint Fk_OrderDetails_Product
Foreign Key (ProductId) References Products(ProductId)
);

Das könnte Ihnen auch gefallen