gpt4 book ai didi

sql - "Invalid Column Name"即使列已创建?

转载 作者:行者123 更新时间:2023-11-29 17:58:12 25 4
gpt4 key购买 nike

我创建了一个表:

create table Praktikant(
Pr_id char not null Primary key,
Name varchar(100) not null,
Mbiemri varchar(100) not null,
Gender char(1) not null,
Degree varchar(100) not null,
age int,
check (age >18),
foreign key (Pr_id) references Doctor(Dr_id) on update cascade
)

插入:

insert into Praktikant values ('1', 'Kastriot', 'Tusha', 'M', 'Student', 19);
insert into Praktikant values ('2', 'Trim', 'Dalipi', 'M', 'Student', 23);
insert into Praktikant values ('3', 'Elira', 'Rrmoku', 'F', 'Studente', 24);
insert into Praktikant values ('4', 'Qendresa', 'Krasniqi', 'F', 'Studente',20);

查询:

    select age
from Praktikant
where age > 23

我不明白为什么会收到此消息:

Msg 207, Level 16, State 1, Line 1
Invalid column name 'age'.

最佳答案

使用此查询获取表信息:

SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'Praktikant'

然后找到您的表架构,因为我怀疑您在另一个架构中有两个同名的表。找到架构后,使用此查询来选择信息:

    select age
from [schema_name].[Praktikant]
where age > 23

您可以使用此查询来获取要检查的表列列表:

SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Praktikant'

关于sql - "Invalid Column Name"即使列已创建?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48630364/

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