I'd to create a database that records transactions between two users. A user can transfer points (think of it as money) to another user. user
table looks like:
| userID | name | email | balance |
| ------------- |---------------|------------------|------------|
| 101 | alpha | [email protected] | 1000 |
| 102 | bravo | [email protected] | 500 |
| 103 | charlie | [email protected] | 2000 |
And the transaction
table should look like:
| transactionID | from_user | to_user | transfer_amount |
| ------------- |---------------|------------------|------------------|
| 1 | 101 | 103 | 100 |
| 2 | 102 | 101 | 150 |
| 3 | 102 | 103 | 200 |
I tried to draw a schema with Vertableo which doesn't seem have one to zero or many relationship option. But a user might not send or receive points at all, so the relationship should be one to zero or many. However, this schema on Vertableo throws the error reference name must be unique.
Could someone give hints to draw a schema or provide SQL code?
CREATE
statements.rdbms
tag, but a tag for the database product you are usingpostgresql
,oracle
,db2
, ...mysql
tag.