简体   繁体   中英

MySQL - creating one primary/unique key for multiple tables

Let's say I've got tables like:


CARS:

columns: "id", "description"

TRUCKS:

columns: "id", "description"


Both tables got primary keys on field "id".

Is it possible to make sth like one 'common', 'combined' key to both of the tables at the same time... the issue is I need to have both "id" unique , ie when I had added TRUCKS : 1, 2, 3, 4..... then adding CARS I need to start from id 5...6,7,8,etc

Table vehicle
id 

Table car
id
id_vehicle
description

Table truck 
id
id_vehicle
description

OR (better? - depends what is Your goal)

Table vehicle
id 
id_vehicle_type
description

Table vehicle_type
id
name

vehicle_type(s): (1,car), (2,truck)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM