-2

I made a database called users in which it has a name, password and phone number, but I want this user to have another table that stores current_capital, current_percentage and current_date of that user but I do not know how to do it, some advice ?

I have the telephone number in the user database as the primary key.

It is advisable to have a database for each user? or better to these attributes (save capital_actual, current_percent and current_date) I add an attribute identifier_user that would be the phone number and put everything in a second table? (as records table)

Thanks.

1 Answers1

0

When using databases, you want to have a data model with a fixed set of tables and columns. You then add data by adding rows to tables. Not tables to databases, or columns to tables, but rows to tables.

From what I can tell, you have two tables connected using a foreign key constraint:

create table users (
    user_id int auto_increment primary key,
    phone_number varchar(255),
    password varchar(255),  -- should be encrypted
    name varchar(255)
);

create table user_daily (
    user_daily_id int auto_increment primary key,
    user_id int,
    current_date date,
    current_capital numeric(10, 2),
    current_percent numeric(5, 4),
    constraint fk_user_daily_users foreign key (user_id) references users(user_id)
);

Note that both tables have auto-incrementing primary keys.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786