瀏覽代碼

Add constraints to car demo

David Ginzberg 7 年之前
父節點
當前提交
7e31d9b620
共有 1 個檔案被更改,包括 4 行新增2 行删除
  1. 4
    2
      src/main/resources/schema-h2.sql

+ 4
- 2
src/main/resources/schema-h2.sql 查看文件

25
   MAKE VARCHAR2(255) not null default '',
25
   MAKE VARCHAR2(255) not null default '',
26
   MODEL varchar2(255) NOT NULL DEFAULT '',
26
   MODEL varchar2(255) NOT NULL DEFAULT '',
27
   YEAR VARCHAR2(5) NOT NULL DEFAULT '01907',
27
   YEAR VARCHAR2(5) NOT NULL DEFAULT '01907',
28
-  PRIMARY KEY (ID)
28
+  PRIMARY KEY (ID),
29
+  CONSTRAINT 'unique_make_model_year' UNIQUE (make, model, year)
29
 );
30
 );
30
 
31
 
31
 CREATE TABLE auto_prices (
32
 CREATE TABLE auto_prices (
32
   id INT PRIMARY KEY AUTO_INCREMENT,
33
   id INT PRIMARY KEY AUTO_INCREMENT,
33
   car_id INT REFERENCES car(id),
34
   car_id INT REFERENCES car(id),
34
   package VARCHAR2(15) NOT NULL,
35
   package VARCHAR2(15) NOT NULL,
35
-  price NUMBER(10,2) NOT NULL CHECK(price > 0)
36
+  price NUMBER(10,2) NOT NULL CHECK(price > 0),
37
+  CONSTRAINT 'unique_package_per_car' UNIQUE (car_id, package)
36
 );
38
 );
37
 
39
 
38
 DROP SEQUENCE hibernate_sequence;
40
 DROP SEQUENCE hibernate_sequence;