开发者

DB2-physical entities with super type sub type logical solution

开发者 https://www.devze.com 2023-03-15 16:29 出处:网络
Does anyone know and tell how to implement physical entities with supe开发者_如何学Gor type sub type logical solution in DB2 database.Its basically the same whatever RDBMS you are using:-

Does anyone know and tell how to implement physical entities with supe开发者_如何学Gor type sub type logical solution in DB2 database.


Its basically the same whatever RDBMS you are using:-

   CREATE TABLE VEHICLES ( 
         V_ID   INTEGER PRIMARY KEY,
         V_DESCRIPTION VARCHAR(20),
         V_MAKE        VARCHAR(20),
         V_MODEL       VARCHAR(20),
         V_COST        DECIMAL(8,2),
         V_ETC         VARCHAR(50),
         V_TYPE        SMALLINT
         -- 1 -> CAR
         -- 2 -> BICYCLE
   );
 CREATE TABLE CARS ( 
         V_ID   INTEGER PRIMARY KEY,
         V_ENGINE_SIZE DECIMAL(6),
         V_SEATS       SMALLINT
   );
 CREATE TABLE BICYCLES (
         V_ID   INTEGER PRIMARY KEY,
         GEARS         SMALLINT
 );

VEHICLES is your supertype which contains attributes common to all vehicles, CARS is a subtype of VEHICLES which contains attributes that pertain only to CARS, the V_TYPE attribute in the VEHICLES table identifies which subtype applies.

The primary keys of the supertype and subtype should be the same value and you can enforce this with a foreign key relationship.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号