danniellee / KNU-20192-08

using java to make account book
0 stars 0 forks source link

Our Databases SQL Source Code #4

Open 7heIVIaze opened 4 years ago

7heIVIaze commented 4 years ago

-- creating the database and related tables create database STORE; use STORE;

-- create Register relation Create table Register ( Id varchar(20) not null, Password varchar(20) not null, Admin boolean, primary key (Id) );

-- create Store relation create table Store ( Name varchar(20) not null, Location varchar(30) not null, Lid varchar(20) not null, -- foreign key from Register Id primary key(Name, Lid) );

-- create Stock relation create table Stock ( Name varchar(20) not null, Cost int(11) not null, Edate datetime, Quantity int not null, Lid varchar(20) not null, Sstore varchar(20) not null, primary key(Name) );

-- create Sales relation create table Sales ( Pname varchar(20) not null, Psales decimal(5,3) not null, Margin int not null, primary key(Pname, Psales) );

7heIVIaze commented 4 years ago

editted

-- creating the database and related tables create database STORE; use STORE;

-- create Register relation Create table Register ( Id varchar(20) not null, Password varchar(20) not null, Admin boolean, primary key (Id) );

-- create Stock relation create table Stock ( Name varchar(20) not null, Cost int(11) not null, Whole int(11) not null, Edate datetime, Quantity int not null, Event boolean, Lid varchar(20) not null, primary key(Name) );

-- create Sales relation create table Sales ( Pname varchar(20) not null, Psales decimal(5,3) not null, Margin int not null, primary key(Pname, Psales) );

7heIVIaze commented 4 years ago

Final Version

-- creating the database and related tables create database STORE; use STORE;

-- create Register relation Create table Register ( Id varchar(20) not null, Password varchar(20) not null, Admin boolean, primary key (Id) );

-- create Stock relation create table Stock ( Name varchar(20) not null, Cost int(11) not null, Whole int(11) not null, Edate datetime, Quantity int not null, Event boolean, Lid varchar(20) not null, primary key(Name, Edate) );

-- create Sales relation create table Sales ( Pname varchar(20) not null, Psales decimal(5,3) not null, Margin int not null, primary key(Pname, Psales) );

-- create foreign key in stock alter table Stock add constraint StockID foreign key (Lid) references Register (Id);

-- create foreign key in sales alter table Sales add constraint SalesName foreigen key (Pname) references Stock (Pname);