#arrays in db?

47 messages · Page 1 of 1 (latest)

wooden stream
#

Hi! How do you create an array in an SQL database? I come from a MongDB background so I'm a little lost about this right now. Help in the right direction is highly appreciated! Thank you!

ivory frost
#

so the thing about sql databases

#

is you don't create arrays

#

you would create a relationship

ivory frost
wooden stream
#

No I don't come from a Java background, but more of JavaScript background.

wooden stream
# ivory frost you would create a relationship

Would you mind explaining a little more?

What I'm trying to do here is to have an array that kinda looks like this:

role1: [person1, person2], 
role2: [person3, person4]

I know I should create a person table, but I'm not sure how to connect person1 and 2 to role1 without the array.

ivory frost
wooden stream
#

Unlimited size in this context. But what is difference in implementation between the two?

ivory frost
#

do many people have many roles?

#

or do many people have 1 role?

wooden stream
#

Many to many relationship

ivory frost
#

yes

#

i would make a many to many relationship

wooden stream
ivory frost
#

Role

#

Person

#

and Role_Person

#

Role should have a role_id

#

Person should have a person_id

#

each record in Role should be a role

#

each record in Person should be a person

#

each record in Role_Person should hold a role_id and a person_id to relate which role a person may have, or in other terms, which person may have a role

#

this gives you maximum flexibility so that many people can have many roles

wooden stream
ivory frost
#

you should only have 3 tables max

#

think of a table like a class

#

a record in a table is like an object

wooden stream
# ivory frost a record in a table is like an object

On a greater scale, I have an entity that encompasses the roles.

Example:

Entity {
  name: ..., 
  type: ..., 
  role1: [person1, person2], 
  role2: [person3, person4]
}

Would the Person_Role table still apply in this context? Or must I create an Entity_Person_role table?

ivory frost
#
Person {
  person_id: ...,
  name: ...,
  type: ...
}
#
Role {
  role_id: ...,
  name: ...
}
#
Person_Role {
  person_id: ...,
  role_id: ...
}
wooden stream
ivory frost
#

does this many roles have to be 2 roles?

wooden stream
ivory frost
#

oh

#

so many people have many roles

wooden stream
ivory frost
#

then yes

#

i would make 3 tables

versed pawn