asp中Access与Sql Server数据库区别总结
时间:2007-11-18 15:08:00
后台数据库: [Microsoft Access] 与 [Microsoft Sql Server] 更换之后,ASP代码应注意要修改的一些地方:
[一]连接问题(举例)
[Microsoft Access]
constr = "DBQ=c:\data\clwz.mdb; DRIVER={Microsoft Access Driver (*.mdb)}"
[Microsoft Sql Server]
constr = "DRIVER={SQL Server};SERVER=host;DATABASE=mydata;uid=sa;pwd="
[二]相似函数(举例)
[1]
DATEDIFF(datepart, startdate, enddate)
其中“datepart”参数可选项如下:
设置 描述
————————————
[Microsoft Access]
年 yyyy
季度 q
月 m
一年的日数 y
日 d
一周的日数 w
周 ww
小时 h
分钟 n
秒 s
[Microsoft Sql Server]
year yy, yyyy
quarter qq, q
month mm, m
dayofyear dy, y
day dd, d
week wk, ww
hour hh
minute mi, n
second ss, s
millisecond ms
基本上差不多,但注意的是在写的时候
[Microsoft Access]要加引号,如:
datediff('d',enddate,'2004/08/01')
[Microsoft Sql Server]则不需要,如:
datediff(d,enddate,'2004/08/01')
[2][Microsoft Access]中可用如cstr等转数据类型函数,而 [Microsoft Sql Server]中则用convert或cast函数,如: convert(varchar,[amount])等。
[3][Microsoft Sql Server] 取当前时间用getdate等等...
[三]语句 [Microsoft Sql Server] 可以用
CASE
WHEN THEN
WHEN THEN
...
ELSE
END
语句,而 [Microsoft Access] 不支持。
[Microsoft Access]也不支持between语句
[Microsoft Sql Server]则可以这样写:
[date] between @date1 and @date2
[四]查询表
[Microsoft Sql Server] 可三个及以上表join查询,而 [Microsoft Access] 好像只能两个表联接查询(待权威确认),而且[Microsoft Sql Server]可用“*=”和“=*”连接符。
[五]除零问题
[Microsoft Access] 在碰到除数为零时,自动丢掉相关记录,而 [Microsoft Sql Server]
则会报错,且查询中止。删除代码:[Microsoft Access] 可以这样写:
delete * from [table]
[Microsoft SQL Server]
只能这样写:
delete from [table]
多*会报错
当前日期: [Microsoft Access] 用date() [Microsoft SQL Server] 用getdate()如果数据库可能会更换类型的话,可以 在ASP代码中加上如这样:
if inStr(constr,"Microsoft Access") > 0 then
sqlstr=[Microsoft Access][sql代码]
else
sqlstr=[Microsoft Sql Server][sql代码]
end if
(constr--连接字符串)
这样即使改了数据库,也不用改数据库查询更新代码了。 再加:access中有true、false的字段记录,而sql里只有smallint,对应如果在access里有“字段名=true”的,在sql里要改成“字段名=1” 网上大部分的免费asp程序使用的是access数据库。但是access数据库作为一个中小型的单机数据库系统,在承担访问量、数据量大的网站应用时,往往就不堪重负了。
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
详解Python如何查看一个函数的参数
Python实现验证码识别
![](https://img.aspxhome.com/file/2023/6/135266_0s.png)
Python Numpy 数组的初始化和基本操作
为ABP框架增加日志组件与依赖注入服务
Python的条件语句与运算符优先级详解
![](https://img.aspxhome.com/file/2023/9/121709_0s.jpg)
python遍历文件夹,指定遍历深度与忽略目录的方法
Python代码实现KNN算法
pyautogui自动化控制鼠标和键盘操作的步骤
![](https://img.aspxhome.com/file/2023/2/101182_0s.png)
Python使用当前时间、随机数产生一个唯一数字的方法
![](https://img.aspxhome.com/file/2023/6/67926_0s.png)
python 反编译exe文件为py文件的实例代码
Python pandas DataFrame数据拼接方法
python中 ? : 三元表达式的使用介绍
IDEA导入Git项目的方法
![](https://img.aspxhome.com/file/2023/5/132245_0s.png)
Django框架中render_to_response()函数的使用方法
初学者快看,Python下划线的五个作用介绍
![](https://img.aspxhome.com/file/2023/7/68297_0s.jpg)
MySQL修改innodb_data_file_path参数的一些注意事项
浅析python中while循环和for循环
SingleFlight模式的Go并发编程学习
![](https://img.aspxhome.com/file/2023/3/133923_0s.jpg)