删除一个表中的记录大家都知道是
delete from table_name where <…..> ,但是您有对比过吗?Delete From Student WHERE Student.sno = 1 可以执行
Delete From Student WHERE sno=1 可以执行
delete from table_name ali_name where ali_name.id=1 可以执行吗 ?
就是通过别名操作的话
在oracle下:
DELETE FROM Student s WHERE s.id =1 可以执行
在Mysql 下:
delete from test.t_user where test.t_user.id=1; 可以执行
Delete From Student WHERE Student.sno = 1 可以执行
Delete From Student WHERE sno=1 可以执行
Delete From Student s WHERE s.sno = 1 出错,不可以执行
sql:
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 5.0.67-community-nt-log MySQL Community Edition (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> user test -> ; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'user test' at line 1 mysql> use test; Database changed mysql> select * from t_user; +----+----------------+------+ | id | name | sex | +----+----------------+------+ | 2 | success insert | 8 | | 3 | success insert | 8 | | 4 | sdf | sdfs | | 5 | sdf | z | | 6 | asdf | 234 | +----+----------------+------+ 5 rows in set (0.00 sec) mysql> delete from test.t_user where id=2; Query OK, 1 row affected (0.06 sec) mysql> select * from t_user; +----+----------------+------+ | id | name | sex | +----+----------------+------+ | 3 | success insert | 8 | | 4 | sdf | sdfs | | 5 | sdf | z | | 6 | asdf | 234 | +----+----------------+------+ 4 rows in set (0.02 sec) mysql> delete from test.t_user t where t.id=3; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where t.id=3' at line 1 mysql> delete from test.t_user t where t.id=3; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where t.id=3' at line 1 mysql> |
Mssql 2005 下:
delete from test_tb where test_tb.id=3 可以执行delete from test_tb where id=3 可以执行
delete from test_tb t where t.id=3 不 可以执行
但是奇怪的是通过hibernate 的hql 语句:
delete from test_tb t where t.id=3 可以执行 (自己模型要对应好哦 )
通过 hibernate 的sql:
delete from test_tb t where t.id=3 不 可以执行