我们想要搜索一些表.
我无法理解为什么会发生这种错误,请帮忙.
对于专家我应该很容易
SELECT * FROM passenger INNER JOIN [passenger-flylist] ppff ON ppp.[passenger-id] = ppff.[passenger-id]
错误 :
消息4104,级别16,状态1,行1
无法绑定多部分标识符"ppp.passenger-id".
表是:
CREATE TABLE [dbo].[passenger]( [passenger-id] [int] IDENTITY(1,1) NOT NULL, [name] [char](50) COLLATE Arabic_CI_AS NOT NULL, [sex] [char](10) COLLATE Arabic_CI_AS NULL, [mobile] [char](20) COLLATE Arabic_CI_AS NULL, [address] [varchar](50) COLLATE Arabic_CI_AS NULL, [flylist-id] [int] NOT NULL, [chair-number] [char](10) COLLATE Arabic_CI_AS NOT NULL, [Age] [char](10) COLLATE Arabic_CI_AS NULL, [ticket-number] [char](10) COLLATE Arabic_CI_AS NULL, CONSTRAINT [PK_passenger] PRIMARY KEY CLUSTERED ( [passenger-id] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] GO
第二
CREATE TABLE [dbo].[flylist]( [flylist-id] [int] IDENTITY(1,1) NOT NULL, [fly-number] [varchar](50) COLLATE Arabic_CI_AS NOT NULL, [go-date] [char](15) COLLATE Arabic_CI_AS NOT NULL, [return-date] [char](15) COLLATE Arabic_CI_AS NOT NULL, [go-time] [char](5) COLLATE Arabic_CI_AS NOT NULL, [return-time] [char](5) COLLATE Arabic_CI_AS NOT NULL, [start-from] [varchar](50) COLLATE Arabic_CI_AS NOT NULL, [destination] [varchar](50) COLLATE Arabic_CI_AS NULL, [airline-company-id] [int] NOT NULL, [airplane-id] [int] NOT NULL, CONSTRAINT [PK_flylist] PRIMARY KEY CLUSTERED ( [flylist-id] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] GO
第三
CREATE TABLE [dbo].[passenger-flylist]( [passenger-id] [int] NOT NULL, [flylist-id] [int] NOT NULL, CONSTRAINT [PK_passenger-flylist] PRIMARY KEY CLUSTERED ( [passenger-id] ASC, [flylist-id] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] GO USE [AirlineSx] GO ALTER TABLE [dbo].[passenger-flylist] WITH CHECK ADD CONSTRAINT [FK_passenger-flylist_passenger-flylist] FOREIGN KEY([passenger-id], [flylist-id]) REFERENCES [dbo].[passenger-flylist] ([passenger-id], [flylist-id])
如果我在设置关系方面遇到问题,请告诉我该怎么做,
谢谢,我发现与你并行,但我得到了另一个错误:(在我的真实代码中,我想获得Passenger-id,但它不允许我)
SELECT [passenger-id] FROM passenger ppp -- <<<< This line INNER JOIN [passenger-flylist] ppff ON ppp.[passenger-id] = ppff.[passenger-id] INNER JOIN flylist fff ON ppff.[flylist-id] = fff.[flylist-id] WHERE ppp.[name] = @name AND fff.[start-from] = @flightDate AND ppp.[ticket-number] = @ticketNo
错误是:
消息209,级别16,状态1,过程SearchForPassenger,第19行
不明确的列名称'passenger-id'.
它指的是我们要选择的第一行[passenger-id]
问题是缺少别名ppp
SELECT * FROM passenger ppp INNER JOIN [passenger-flylist] ppff ON ppp.[passenger-id] = ppff.[passenger-id]