CREATE TABLE user (
  id INT NOT NULL AUTO_INCREMENT,
  name VARCHAR(20) NOT NULL, 
  password VARCHAR(20) NOT NULL, 
  CONSTRAINT pk PRIMARY KEY (id)
);

CREATE TABLE cash (
  userId int primary key, 
  cash int not null default 0, 
  foreign key (userId) references user(id)
);

CREATE TABLE holding (
  buyerId int not null, 
  subjectId int not null, 
  percentage double not null, 
  foreign key (buyerId) references user(id), 
  foreign key (subjectId) references user(id), 
  constraint pk primary key (buyerId, subjectId)
);

CREATE TABLE price (
  userId int primary key, 
  price int not null default 0, 
  foreign key (userId) references user(id)
);

CREATE TABLE priceHistory (
  id int primary key AUTO_INCREMENT,
  userId int not null,
  price float not null,
  date date not null,
  isDay bit not null,
  constraint u unique (userId, date, isDay),
  foreign key (userId) references user(id)
);

CREATE TABLE ranking (
  rankerId int not null,
  rankeeId int not null,
  ranking float not null,
  constraint pk primary key (rankerId, rankeeId),
  foreign key (rankerId) references user(id),
  foreign key (rankeeId) references user(id)
);
