Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't (directly). Relational databases don't have arrays; they have tables (relations) and relationship between them. Consequently, SQL doesn't have the notion of an array.</p> <p>You could do something like:</p> <pre><code>create table foo ( id int not null primary key , col_01 varchar(200) null , col_02 varchar(200) null , ... col_nn varchar(200) null , ) </code></pre> <p>but that is <a href="http://en.wikipedia.org/wiki/Database_normalization#Normal_forms" rel="nofollow">non-normal</a>, violating <a href="http://en.wikipedia.org/wiki/First_normal_form" rel="nofollow">1st Normal Form</a>: it has repeating groups.</p> <p>The schema you want is something like</p> <pre><code>create table book ( id int not null primary key , -- primary key isbn varchar(32) null , title varchar(80) not null , -- can't use title as a key as titles are not unique ) -- you might have multiple copies of the same book create table book_copy ( book_id int not null , copy_number int not null , primary key ( book_id , copy_number ) , foreign key ( book_id ) references book(id) , ) create table customer ( id int not null primary key , surname varchar(32) not null , name varchar(32) not null , ) create table customer_has_book ( customer_id int not null , book_id int not null , copy_number int not null , primary key ( customer_id , book_id , copy_number ) , -- customer+book+copy number is unique unique ( book_id , copy_number ) , -- a given copy may only be borrowed one at a time foreign key ( customer_id ) references customer(id) , foreign key ( book_id , copy_number) references book_copy(book_id,copy_number) , ) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload