不同数据库delete 使用别名的差别

删除一个表中的记录大家都知道是

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  可以执行
 

  

 

 

 

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

«    2024年11月    »
123
45678910
11121314151617
18192021222324
252627282930
搜索
标签列表
网站分类
最新留言
    文章归档
    友情链接

    Powered By Z-BlogPHP 1.7.3

    Copyright Your WebSite.Some Rights Reserved.闽ICP备11018667号-2