How do you create the table structure in PostgreSQL to make a many-to-many relationship

Viewed 32

my example so far I would like to know how to create a many to many relationship with these.


CREATE TABLE accounts ( 
    id SERIAL,
    first_name VARCHAR(50),
    last_name VARCHAR (50),
    username VARCHAR (50),
    password VARCHAR (500),
    account_Type VARCHAR (10),
    bday VARCHAR (50),
    PRIMARY KEY(id)
    );
CREATE TABLE bank_account(
    id SERIAL,
    account_number INTEGER PRIMARY KEY,
    account_balance INTEGER
);
1 Answers

you can create a table like this one:

CREATE TABLE bank_account_accounts(
        id serial primary key,
        accounts_id integer,
        bank_account_id integer
    );
Related