create table "users"(
"id" SERIAL PRIMARY KEY NOT NULL,
"full_name" varchar(100) NOT NULL,
"role" integer NOT NULL DEFAULT 0,
"email" varchar(100) NOT NULL
);
create table "devices"(
"id" SERIAL PRIMARY KEY NOT NULL,
"brand_name" varchar(20) NOT NULL
);
create table "users_and_devices"(
"user_id" integer NOT NULL,
"device_id" integer NOT NULL,
foreign key (user_id) references users(id),
foreign key (device_id) references devices(id)
);
我怎样才能得到brand_name
属于的所有设备user 1
?我应该在user_id
和device_id
中添加索引users_and_devices
吗?
谢谢你。