我在SQL Management Studio中创建了一个视图并且它工作正常但是当我按特定ID搜索数据时会出现问题,它会显示多行数据。 注意:View从两个表中获取数据,这些表包含一个相同的ID列,同一列的名称是“Reservation ID” 我附上了一个场景图片。请指导我在哪里弄错了。
谢谢
select Reservation.Reservation_ID
,Reservation.Customer_ID
,Reservation.Exact_Arrival
,Reservation.Exact_Departure,Reservation.Number_of_Persons
,Reservation.Room_Floor
,Reservation.Room_Number
,Reservation.Room_Type
,Reservation.Vehicle_Number
,CustomersDetails.Customer_Address
,CustomersDetails.Customer_CNIC
,CustomersDetails.Customer_Full_Name
,CustomersDetails.Customer_Phone_Number
from Reservation,CustomersDetails;
答案 0 :(得分:3)
根据您和我的评论,您似乎需要以不同的方式构建视图。您当前正在从两个表中转储所有信息而没有连接。 建立你的视图,
create view [dbo].[V_Information]
As select Reservation.Reservation_ID,
Reservation.Customer_ID,
Reservation.Exact_Arrival,
Reservation.Exact_Departure,
Reservation.Number_of_Persons,
Reservation.Room_Floor,
Reservation.Room_Number,
Reservation.Room_Type,
Reservation.Vehicle_Number,
CustomersDetails.Customer_Address,
CustomersDetails.Customer_CNIC,
CustomersDetails.Customer_Full_Name,
CustomersDetails.Customer_Phone_Number
from
Reservation
INNER JOIN CustomersDetails
ON Reservations.Customer_ID = CustomerDetails.Customer_ID;