Diseño de tablas SQL para novatos

Watch out, learning sql newbie. I would like to create 2 simple tables.

products: id | product_name

order_table: id | buyer_name | purchased_products

CREATE TABLE products (
  id INTEGER PRIMARY KEY, 
  product_name TEXT
  );

CREATE TABLE order_table (
  id INTEGER PRIMARY KEY,
  buyer_name TEXT,
  purchased_products NUMERIC ARRAY
  );

Currently the link is numeric, but this would require the report generation to know that purchased_products is referring to the products table. Is it possible to define that the purchased_products must be referring to the products?

Note: this is sqlite3,

preguntado el 09 de marzo de 12 a las 14:03

1 Respuestas

Quitar el campo purchased_products and create one more table, like this:

order_product: id | order_id | product_id

Now, you should declare that order_id is a foreign key referring to the field id de la mesa order_table, and that product_id does the same for products.

respondido 09 mar '12, 14:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.