I got this example to work with some help on here:
http://sqlfiddle.com/#!2/92e87/1
However, if I want to try and insert information for every child of the table, I cant seem to get it to work (using this code):
CREATE TABLE country (
id integer NOT NULL PRIMARY KEY AUTO_INCREMENT,
name varchar(255) NOT NULL
)
;
CREATE TABLE location (
id integer NOT NULL PRIMARY KEY AUTO_INCREMENT,
name varchar(255) NOT NULL,
coordinate varchar(255) NOT NULL,
country_id integer NOT NULL REFERENCES country (id)
)
;
CREATE TABLE item (
id integer NOT NULL PRIMARY KEY AUTO_INCREMENT,
title varchar(60) NOT NULL,
description varchar(900) NOT NULL,
date datetime NOT NULL,
source varchar(255) NOT NULL,
link varchar(255) NOT NULL,
location_id integer NOT NULL REFERENCES location (id)
)
;
Insert Into item (title) values ('Title');
Insert Into item (description) values ('Description');
Insert Into item (date) values ('1995-12-31T23:59:59Z');
Insert Into item (source) values ('Source');
Insert Into item (link) values ('Link');
Insert Into item (location_id) values ('1');
Is this the correct way of doing this? Secondly, it tells me “description” doesnt have a default value, but does it need one if I will always be putting information into it?
Thank you for any help you can give
Each insert acts as inserting a new record. hence you need to combine all data into one insert statement as given above.
The SQL asks for default value, because you have mentioned
NOT NULLin the table definition which you have created.