1

I have a doubt regarding the construction of a database ( sql ) . I'm simulating the database of a bank , and the transaction table have an attribute type transaction , how do I indicate that this attribute can be either withdrawal , deposit or bank ? which are other tables in my database . Thanks in advance

Daniele
  • 704
  • 1
  • 6
  • 22

1 Answers1

0

You can't do that with constraints. But you can do something like this: set two fields in the transactions table (transaction_type and transaction_id) and then you can use numbers (or strings) to refer to each table. For example: transaction_type 1 can refers to deposits table. Then, in your code, you can search for the record with id = transactions.transaction_id on the deposits table.

Check this answer.

Community
  • 1
  • 1
Gabriel Moretti
  • 676
  • 8
  • 23