红联Linux门户
Linux帮助

SQL Server与 Access在SQL语法上的差异

发布时间:2006-10-17 22:45:42来源:红联作者:linuxcms
引:SQL Server、Microsoft Access都是微软的产品。前者用于中型企业级应用,后者是小型数据库的代表,初学者易于掌握。在开发一般信息系统时,尤其是单机版,大都采用Access。虽然SQL Server也有个人桌面版,但是运行时需占用较多的系统资源。
[font=宋体]在局域网广泛应用的形势下,网络版软件大行其道,不少软件从单机版过渡到[/font][font=Times New Roman]C/S[/font][font=宋体]模式的网络应用,通过[/font][font=Times New Roman]SQL[/font][font=宋体]语句从服务端获取数据集,将查询结果返回给客户端。[/font]
[font=Times New Roman]Access[/font][font=宋体]中提供查询对象,在设计时可以采用设计视图和[/font][font=Times New Roman]SQL[/font][font=宋体]视图,非常方便,[/font][font=Times New Roman]SQL[/font][font=宋体]视图中的[/font][font=Times New Roman]SQL[/font][font=宋体]语句可以在[/font][font=Times New Roman]SQL SERVER[/font][font=宋体]中使用,但是否完全可用呢?答案是否定的,表[/font][font=Times New Roman]1[/font][font=宋体]中总结了[/font][font=Times New Roman] Microsoft Access [/font][font=宋体]和[/font][font=Times New Roman] Microsoft SQL Servers [/font][font=宋体]的[/font][font=Times New Roman] SQL [/font][font=宋体]语法的重要区别。[/font][font=Times New Roman] [/font]
[font=宋体]表[/font][font=Times New Roman]1[/font][table=98%][tr][td=1,1,26%][align=center][font=Times New Roman]SQL [/font][font=宋体]语法元素[/font][/size][/align][/td][td=1,1,33%][align=center][font=Times New Roman]Microsoft
Access
[size=12pt]
[/font][/align][/td][td=1,1,39%][align=center][font=Times New Roman]Microsoft SQL
Server
[/size][/font][/align][/td][/tr][tr][td=1,1,26%][font=宋体]标识符[/font][size=12pt]
[/td][td=1,1,33%][font=宋体]限制不超过[/font][font=Times New Roman] 64 [/font][font=宋体]个字符。[/font][font=Times New Roman] [/font]
[font=宋体]允许使用关键字和特殊字符。[/font]
[font=宋体]可以用任何字符开头。[/font][/color]
[/td][td=1,1,39%][font=Times New Roman]SQL Server 6.5[/font][font=宋体]:[/font]
[list][font=宋体]限制不超过[/font][font=Times New Roman] 30 [/font][font=宋体]个字符。[/font] [font=宋体]不允许使用关键字和特殊字符。[/font] [*][font=宋体]必须用字母字符开头。[/font][font=Times New Roman] [/font][/list][list=1][/size][/list][size=3]SQL Server 7.0 [font=宋体]的标识符与[/font] Access [font=宋体]完全兼容。[/font][color=windowtext]
[/td][/tr][tr][td=1,1,26%][font=宋体]输出字段[/font][size=12pt]
[/size][/td][td=1,1,33%][font=宋体]允许多个输出字段具有相同名称。[/font][size=12pt]
[/size][/td][td=1,1,39%][font=宋体]在视图中不支持多个相同输出字段名。[/font][size=12pt]
[/size][/td][/tr][tr][td=1,1,26%][font=宋体]日期分隔符号[/font][size=12pt]
[/size][/td][td=1,1,33%][font=宋体]英镑符([/font][font=Times New Roman]#[/font][font=宋体])[/font][size=12pt]
[/size][/td][td=1,1,39%][font=宋体]撇号([/font][font=Times New Roman]'[/font][font=宋体])[/font][size=12pt]
[/size][/td][/tr][tr][td=1,1,26%][font=Times New Roman]Boolean [/font][font=宋体]常量[/font][size=12pt]
[/size][/td][td=1,1,33%][font=Times New Roman]True[/font][font=宋体]、[/font][font=Times New Roman]False[/font][font=宋体];[/font][font=Times New Roman]On[/font][font=宋体]、[/font][font=Times New Roman]Off[/font][font=宋体];[/font][font=Times New Roman]Yes[/font][font=宋体]、[/font][font=Times New Roman]No[/font][font=宋体]。[/font][size=12pt]
[/size][/td][td=1,1,39%][font=宋体]整数:[/font][font=Times New Roman]1[/font][font=宋体](真)、[/font][font=Times New Roman]0[/font][font=宋体](假)[/font][font=Times New Roman] [size=12pt][/font]
[/size][/td][/tr][tr][td=1,1,26%][font=宋体]字符串连接[/font][size=12pt]
[/size][/td][td=1,1,33%][font=宋体]和号([/font][font=Times New Roman]&[/font][font=宋体])[/font][size=12pt]
[/size][/td][td=1,1,39%][font=宋体]加号([/font][font=Times New Roman]+[/font][font=宋体])[/font][size=12pt]
[/size][/td][/tr][tr][td=1,1,26%][font=宋体]通配符[/font][size=12pt]
[/size][/td][td=1,1,33%][font=宋体]星号([/font][font=Times New Roman]*[/font][font=宋体])与零个或更多字符匹配。[/font][font=Times New Roman] [/font]
[font=宋体]问号([/font]?[font=宋体])与单个字符匹配。[/font]
[font=宋体]叹号([/font]![font=宋体])意味着不在列表中。[/font]
[font=宋体]英镑符([/font]#[font=宋体])意味着单个数字。[/font][color=windowtext][/color]
[/td][td=1,1,39%][font=宋体]百分号([/font][font=Times New Roman]%[/font][font=宋体])与零个或更多字符匹配。[/font][font=Times New Roman] [/font]
[font=宋体]下划线([/font]_[font=宋体])与单个字符匹配。[/font]
[font=宋体]上插入符([/font]^[font=宋体])意味着不在列表中。[/font]
[font=宋体]没有与英镑符([/font]#[font=宋体])对应的字符。[/font]
[/td][/tr][tr][td=1,1,26%][font=Times New Roman]TOP[size=12pt][/font]
[/size][/td][td=1,1,33%][font=宋体]如果有一个[/font][font=Times New Roman] ORDER BY [/font][font=宋体]子句,自动包含层次。[/font][size=12pt]
[/size][/td][td=1,1,39%][font=Times New Roman]SQL Server 6.5 [/font][font=宋体]不支持。[/font][font=Times New Roman] [/font]
SQL Server 7.0 [font=宋体]需要一个明确的[/font] WITH TIES [font=宋体]子句。[/font]
[/td][/tr][tr][td=1,1,26%][font=Times New Roman]CREATE INDEX[size=12pt][/font]
[/size][/td][td=1,1,33%][font=宋体]允许创建升序和降序索引。[/font][font=Times New Roman] [/font]
[font=宋体]允许声明主键,没有[/font] Null [font=宋体]值,并且忽略[/font] Null [font=宋体]值。[/font]
[/td][td=1,1,39%][font=Times New Roman][size=12pt][/font]
[/size][/td][/tr][tr][td=1,1,26%][font=Times New Roman]DROP INDEX[/font]
[/td][td=1,1,33%][font=宋体]语法是:[/font][font=Times New Roman] [/font]
Drop Index ON
[/td][td=1,1,39%][font=宋体]语法是:[/font][font=Times New Roman] [/font]
Drop Index
,
[/td][/tr][tr][td=1,1,26%][font=Times New Roman]DISTINCTROW[/font]
[/td][td=1,1,33%][font=宋体]支持(允许选择单个记录)。[/font]
[/td][td=1,1,39%][font=宋体]不支持。[/font]
[/td][/tr][tr][td=1,1,26%][font=Times New Roman]OWNERACCESS[/font]
[/td][td=1,1,33%][font=宋体]支持(在执行时控制许可权)。[/font]
[/td][td=1,1,39%][font=宋体]不支持。[/font]
[/td][/tr][tr][td=1,1,26%][font=Times New Roman]Table in UNION[/font]
[/td][td=1,1,33%][font=宋体]支持(允许使用下列语法指定表:[/font][font=Times New Roman] [/font]
TABLE
[/td][td=1,1,39%][font=宋体]不支持。[/font]
[/td][/tr][tr][td=1,1,26%][font=Times New Roman]ORDER BY in Unions[/font]
[/td][td=1,1,33%][font=宋体]支持。允许通过联合查询中的子句实现多种排序。[/font]
[/td][td=1,1,39%][font=宋体]支持。允许通过语句末尾的子句实现一种排序。[/font]
[/td][/tr][tr][td=1,1,26%][font=Times New Roman]TRANSFORM[/font]
[/td][td=1,1,33%][font=宋体]支持。用于交叉表查询。[/font]
[/td][td=1,1,39%][font=宋体]不支持。[/font]
[/td][/tr][tr][td=1,1,26%][font=Times New Roman]PARAMETERS[/font]
[/td][td=1,1,33%][font=宋体]支持(在[/font][font=Times New Roman] SQL [/font][font=宋体]中记录)。[/font]
[/td][td=1,1,39%][font=宋体]不支持。[/font]
[/td][/tr][/table][font=Times New Roman][/font]
[font=宋体]以[/font]northwind[font=宋体]数据库为例,若要得到相同查询结果,[/font]SQL[font=宋体]语句作相应变化[/font][font=宋体]。[/font]
Access[font=宋体]:[/font]
SELECT * FROM Products where productname like 'c*';
SELECT * FROM Products where productname like 'c?ang';
SQL Server:
SELECT * FROM Products WHERE productname LIKE 'c%'
SELECT * FROM Products WHERE productname LIKE 'c_ang'
[font=宋体]在开发过程中尤其需要注意通配符的变化。[/font]
文章评论

共有 0 条评论