Modello relazionale

Una tabella: relazione uno-a-uno

id nome cognome mail universo
ts tony stark stark@marvel.com marvel
bw bruce wayne wayne@dc.com dc
sr steve rogers rogers@marvel.com marvel

id,nome,cognome,mail,universo
ts,tony,stark,stark@marvel.com,marvel
bw,bruce,wayne,wayne@dc.com,dc

sr,steve,rogers,rogers@marvel.com,marvel

Un csv

Modello relazionale

Una tabella: selezione, ordinamento, raggruppamento

universo supereroi
marvel 2
dc 1

SELECT universo, COUNT(id) AS supereroi

FROM personaggi

GROUP BY universo

ORDER BY supereroi DESC

Modello relazionale

Due tabelle: relazione uno-a-molti

id nome cognome mail universo
ts tony stark stark@marvel.com marvel
bw bruce wayne wayne@dc.com dc
sr steve rogers rogers@marvel.com marvel
id ragione sociale sede sito
marvel Marvel Comics New York http://marvel.com/
dc DC Comics Burbank http://www.dccomics.com/

Modello relazionale

Due tabelle: operazione di join

id nome cognome universo sede
sr steve rogers marvel New York
ts tony stark marvel New York
bw bruce wayne dc Burbank

SELECT personaggi.id, nome, cognome, universo, sede

FROM personaggi JOIN universi ON personaggi.universo = universi.id

ORDER BY cognome

Modello relazionale

Due tabelle: operazione di join

Modello relazionale

Tre tabelle: relazione molti-a-molti

id nome cognome mail
ts tony stark stark@marvel.com
bw bruce wayne wayne@dc.com
sr steve rogers rogers@marvel.com
id descrizione
av The Avengers
jl Justice League
id supereroe team
1 ts av
2 sr av
3 bw jl

JSON

JavaScript Object Notation

id nome cognome mail universo
ts tony stark stark@marvel.com marvel
bw bruce wayne wayne@dc.com dc
[
  {
    "id": "ts",
    "nome": "tony",
    "cognome": "stark",
    "mail": "stark@marvel.com",
    "universo": "marvel"
  },
  {
    "id": "bw",
    "nome": "bruce",
    "cognome": "wayne",
    "mail": "wayne@dc.com",
    "universo": "dc"
  }
]
{
  "id": ["ts","bw"],
  "nome": ["tony","bruce"],
  "cognome": ["stark","wayne"],
  "mail": ["stark@marvel.com","wayne@dc.com"],
  "universo": ["marvel","dc"]
}
{
  "keys": ["id","nome","cognome","mail","universo"],
  "values": [
    ["ts","tony","stark","stark@marvel.com","marvel"],
    ["bw","bruce","wayne","wayne@dc.com","dc"],
  ]
}

JSON

JavaScript Object Notation

id nome cognome mail universo
ts tony stark marvel
bw bruce wayne wayne@dc.com dc
[
  {
    "id": "ts",
    "nome": "tony",
    "cognome": "stark",
    "universo": "marvel"
  },
  {
    "id": "bw",
    "nome": "bruce",
    "cognome": "wayne",
    "mail": "wayne@dc.com",
    "universo": "dc"
  }
]
[
  {
    "id": "ts",
    "nome": "tony",
    "cognome": "stark",
    "universo": "marvel",
    "team": ["av","jl"]
  },
  {
    "id": "bw",
    "nome": "bruce",
    "cognome": "wayne",
    "mail": "wayne@dc.com",
    "universo": "dc",
    "team": ["jl"]
  }
]

JSON

JavaScript Object Notation

id nome cognome mail universo
ts tony stark marvel
bw bruce wayne wayne@dc.com dc
[
  {
    "id": "ts",
    "nome": "tony",
    "cognome": "stark",
    "universo": {
        "id": "marvel",
        "ragione sociale": "Marvel Comics",
        "sede": "New York"
    },
    "team": [
        { "id": "av", "descrizione": "The Avengers" },
        { "id": "jl", "descrizione": "Justice League" }
    ]
  }
]

Strutture dati: tabelle e json

By Dataninja srls

Strutture dati: tabelle e json

Un'introduzione molto basica al modello relazionale e all'approccio NoSQL, confrontando la rappresentazione a tabella con quella JSON.

  • 2,079