habuma / spring-in-action-6-samples

Sample code from Spring in Action 6
484 stars 339 forks source link

This needs to be unique #6

Open umutdogan opened 2 years ago

umutdogan commented 2 years ago

https://github.com/habuma/spring-in-action-6-samples/blob/33acc6497f9a98a3ba8dfe980fd00b87ce0dee5b/ch03/tacos-jdbctemplate/src/main/resources/schema.sql#L30

f-mda commented 2 years ago

Yes, had the same issue when doing Chapter 3, need to define it as unique or just call it a primary key

dainank commented 1 year ago

Yes, had the same issue when doing Chapter 3, need to define it as unique or just call it a primary key

@f-mda Why has this not been updated in the book? Could throw some people off:

create table if not exists Ingredient (
  id varchar(4) primary key not null,
  name varchar(25) not null,
  type varchar(10) not null
);
hasanraj3100 commented 11 months ago

This also worked for me:

create table if not exists Ingredient (
id varchar(4) not null,
name varchar(25) not null,
type varchar(10) not null,
unique(id)
);
dainank commented 11 months ago

This also worked for me:

CREATE TABLE IF NOT EXISTS ingredient
 (
    id   VARCHAR(4) NOT NULL,
    name VARCHAR(25) NOT NULL,
    type VARCHAR(10) NOT NULL,
    UNIQUE(id)
 ); 

Maybe wrap the code within your comment in sql format just for readability.