I just wrote this DELETE
query in SQL Server 2012 and I get an error:
我刚刚在SQL Server 2012中编写了这个DELETE查询,我收到一个错误:
Incorrect syntax near the keyword 'INNER'.
关键字“INNER”附近的语法不正确。
when I execute it. Can anyone help?
当我执行它。有人可以帮忙吗?
DELETE FROM Nhanvien
INNER JOIN Hoadon ON Nhanvien.MaNV = Hoadon.MaNV
WHERE YEAR(Ngaysinh) = '1994'
在此处输入图像描述
EDIT:
2 个解决方案
#1
1
You can use DELETE FROM FROM
more info Why does DELETE FROM … FROM … not error out
:
您可以使用DELETE FROM FROM more info为什么DELETE FROM ... FROM ...没有错误输出:
DELETE
FROM #Nhanvien
FROM #Nhanvien
JOIN #Hoadon ON #Nhanvien.MaNV=#Hoadon.MaNV
WHERE YEAR(Ngaysinh)='1994';
You can skip first FROM
and use:
您可以先跳过FROM并使用:
DELETE #Nhanvien
FROM #Nhanvien
JOIN #Hoadon ON #Nhanvien.MaNV=#Hoadon.MaNV
WHERE YEAR(Ngaysinh)='1994';
Warning
You should prefix Ngaysinh
column with table name. I've assumed it is from #Nhanvien
table in my demos.
你应该在Ngaysinh列前加上表名。我以为它来自我演示的#Nhanvien表。
#2
0
You need to explicitly define which table you are deleting from:
您需要明确定义要删除的表:
DELETE n
FROM Nhanvien n
INNER JOIN Hoadon h ON n.MaNV = h.MaNV
WHERE YEAR(n) = '1994'
#1
1
You can use DELETE FROM FROM
more info Why does DELETE FROM … FROM … not error out
:
您可以使用DELETE FROM FROM more info为什么DELETE FROM ... FROM ...没有错误输出:
DELETE
FROM #Nhanvien
FROM #Nhanvien
JOIN #Hoadon ON #Nhanvien.MaNV=#Hoadon.MaNV
WHERE YEAR(Ngaysinh)='1994';
You can skip first FROM
and use:
您可以先跳过FROM并使用:
DELETE #Nhanvien
FROM #Nhanvien
JOIN #Hoadon ON #Nhanvien.MaNV=#Hoadon.MaNV
WHERE YEAR(Ngaysinh)='1994';
Warning
You should prefix Ngaysinh
column with table name. I've assumed it is from #Nhanvien
table in my demos.
你应该在Ngaysinh列前加上表名。我以为它来自我演示的#Nhanvien表。
#2
0
You need to explicitly define which table you are deleting from:
您需要明确定义要删除的表:
DELETE n
FROM Nhanvien n
INNER JOIN Hoadon h ON n.MaNV = h.MaNV
WHERE YEAR(n) = '1994'