gpt4 book ai didi

SQL 查询错误 : Invalid Column Name

转载 作者:行者123 更新时间:2023-12-02 03:32:43 25 4
gpt4 key购买 nike

我是 SQL 的新手,我遇到了这个问题,我似乎无法在谷歌上搜索。这是我的学校作业,所以请耐心等待我的编码。现在的问题是我正在执行一个选择查询,而 SQL 似乎无法识别我需要的列

这里附上一张图片,上面只是说无效的列,但很明显该列是存在的

Dropbox link to the picture

完整代码如下

create database Hairsalon

use Hairsalon

create table Employee
(
Employee_ID int primary key,
Name varchar(20),
Birthday date,
Gender char(1)
);

create table Inventory
(
Inventory_ID int primary key,
Name varchar(30),
Stock int
)

create table Record
(
Transaction_Number int primary key,
Transaction_Date date,
Transaction_Time time
);

alter table Record
drop column Transaction_Date
alter table Record
drop column Transaction_Time
alter table Record
add Transaction_DT varchar(30)
alter table Record
add Transaction_Description varchar(255)

Create table Inventory_Record
(
Transaction_Number int primary key foreign key references Record(Transaction_Number),
Inventory_ID int foreign key references Inventory(Inventory_ID),
);

create table Customer_Record
(
Transaction_Number int foreign key references Record(Transaction_Number),
Customer_ID int primary key,
Service_Description varchar(255),
Pay money
);

create table Customer
(
Customer_ID int foreign key references Customer_Record(Customer_ID),
Name varchar(20),
Payable money,
Session_DT varchar(20)
);

create table Employee_Record
(
Transaction_Number int primary key foreign key references Record(Transaction_Number),
Employee_ID int foreign key references Employee(Employee_ID),
Time_In time,
Time_Out time,
Record_Date date,
Customer_Count int
);

create table Salon
(
Customer_ID int foreign key references Customer_Record(Customer_ID),
Employee_ID int foreign key references Employee(Employee_ID),
Inventory_ID int foreign key references Inventory(Inventory_ID),
Transaction_Number int foreign key references Record(Transaction_Number)
);

alter table Customer
add Session_DT varchar(20)

alter table Customer
drop column Customer_ID
alter table Customer
add Customer_ID int foreign key references Customer_Record(Customer_ID)

alter table Customer_Record
add Employee_ID int foreign key references Employee(Employee_ID)

alter table Employee
add [Type] varchar(15)

alter table Employee
drop column Birthday
alter table Employee
drop column Birthday

alter table Employee_Record
drop column Time_In
alter table Employee_Record
drop column Time_Out
alter table Employee_Record
drop column Record_Date
alter table Employee_Record
add Time_In varchar(20)
alter table Employee_Record
add Time_Out varchar(20)
alter table Employee_Record
add Record_Date varchar(20)
alter table Employee_Record
drop column Customer_Count

insert into Employee
values(1,'Test Employee','M','Cashier','bday')
insert into Employee
values(-1,'Null','N','Null','Null')
insert into Employee values(1,'test1','M','HairDresser','9/8/2014')

INSERT INTO Record values(2,'')
INSERT INTO Customer_Record values(1,1,'asd',123.00,null)
INSERT INTO Customer values(1,'test1',0,'9/8/2014 8:16 AM')

SELECT * FROM Record
select * from Customer
SELECT * FROM Customer_Record
SELECT * FROM Employee

SELECT DISTINCT Customer.Name as 'Customer Name', Employee.Name as 'Attendee'
FROM Customer, Customer_Record, Employee_Record, Employee
WHERE ( Customer_Record.Transaction_Number = Employee_Record.Transaction_Number
AND Employee_Record.Employee_ID = Employee.Employee_ID
AND Customer.Customer_ID = Customer_Record.Customer_ID
) OR ( Customer_Record.Transaction_Number = Employee_Record.Transaction_Number
AND Customer_Record.Employee_ID = -1
AND Customer.Customer_ID = Customer_Record.Customer_ID
)

insert into Employee_Record values(9,1,'10:00','10:99','date')

select * from Record
select * from Customer
select * from Employee
select * from Employee_Record
select * from Customer_Record

select count(Customer_ID) from Customer
select count(Transaction_Number) from Record

insert into Customer
values(1,'test',120,DATEFROMPARTS(32,12,31))

INSERT INTO Customer_Record values(1,1,'Long Haired Customer: ',0, null)

DELETE FROM Customer WHERE Customer_ID = 1

DELETE FROM Customer
DELETE FROM Customer_Record
DELETE FROM Record

DELETE FROM Employee
DELETE FROM Employee_Record
DELETE FROM Inventory
DELETE FROM Inventory_Record

commit

最佳答案

根据您提供的 DDL,很明显 Customer_Record 没有 Employee_ID。

您可能将 Customer_Record 与 Employee_Record 或 Employee_ID 与 Customer_ID 混淆了,但出了点问题。

编辑 我错过了您更改脚本中的表格以添加缺失列的情况。在这种情况下,除非您手动重新加载它(使用 Ctrl + Shift + R),否则 Intellisense(自动完成系统)不会考虑它。您的查询是正确的,一旦 Intellisense 是最新的,错误就会消失。

关于SQL 查询错误 : Invalid Column Name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25719505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com