CREATE VIEW view_college_student(collegeno,college) AS select college.collegeno,college.collegename,student.sno,student.sname FROM student join student on college.collegeno=student.collegeno;CREATE VIEW view_college_student(collegeno,college,sno,sname) AS SELECT college.collegeno,college.collegename,student.sno,student.sname FROM college JOIN student ON college.collegeno=student.collegeno; ERROR 1054 (42S22): Unknown column 'college.collegeno' in 'field list' ERROR 1146 (42S02): Table 'student.college' doesn't exist并没有成功反而报错两个
时间: 2023-12-13 20:03:07 浏览: 101
SQL-CREATE-DATABASE.rar_SQL CREATE DATABASE_stud
根据你提供的 SQL 语句,第一个错误可能是因为你在 JOIN 语句中使用了两个相同的表名 student,导致无法识别 college 表。你可以尝试修改为以下语句:
```
CREATE VIEW view_college_student(collegeno,college) AS
SELECT college.collegeno,college.collegename,student.sno,student.sname
FROM college
JOIN student ON college.collegeno=student.collegeno;
```
在这个语句中,我们将 JOIN 语句中的第二个 student 表名修改为 college,以便正确识别该表。
对于第二个错误,可能是因为在你创建视图之前,数据库中并没有名为 college 和 student 的表。你可以先确认一下这两个表是否存在,如果不存在,需要先创建这两个表才能创建视图。
阅读全文