Home Database Mysql Tutorial 将现有的Access数据库升级为SQL

将现有的Access数据库升级为SQL

Jun 07, 2016 pm 03:17 PM
access sql upgrade database

很多Access和SQL Server开发人员都经常面临着将一个Access数据库升级到SQL Server数据库的问题。由于存在现有的Access升级向导,这一转变的过程就会变得相当简单,尤其是当你建立一个与SQL Server数据相联系的ADP的时候。然而,向导并不是十全十美的,需要解


很多Access和SQL Server开发人员都经常面临着将一个Access数据库升级到SQL Server数据库的问题。由于存在现有的Access升级向导,这一转变的过程就会变得相当简单,尤其是当你建立一个与SQL Server数据相联系的ADP的时候。然而,向导并不是十全十美的,需要解决的问题还是大有存在。


首先,有些对象并不是简单的升级,所以这时你不得不人为地处理。第二,很多Access特性──比如一些查询类型,对象,以及特定的数据类型在你没有做好升级之前的准备的情况下就会导致错误的产生。现在,让我们讨论一下在数据库升级过程中可能面临的问题,我将提供能够解决问题的一些通用的指导方法,最后,你必须花一定的时间和精力将这些知识应用到开发之中。

哪些不能够升级?
在处理实际的问题之前,让我们看看不能随意升级的对象,它们包括以下:

交叉表查询
包含SQL DISTINCTROW关键字的任何查询
所有的隐藏对象
作为参数的表格数据的查询(这些表格可以升级,但它们却不能正确的运行)
Pass-Through查询
SQL数据定义语言查询(比如CREATE TABLE, ALTER TABLE, 以及DROP语句)
这些Access对象需要特定的处理。具体的,你将建立一个可比较的SQL Server对象,除此之外,SQL Server不支持Jet安全特性,所以你必须使用Windows认证和/或SQL Server安全机制。

包括的问题点
在数据库的升级之前,如果你已经知道哪些地方将可能导致错误并知道如何处理产生的错误,数据库升级过程中导致的错误的可能性将大大地减少。我能够提供的数据库升级的最好的建议是在开发之前做好最完整的计划。现在,我将列举数据库升级过程中可能会导致产生的问题──如果你没有做好计划之前的准备。

不支持的日期
 
关于日期,在Access和SQL Server之间都存在很大的差别。Access支持很大范围的日期,从100年1月1日到9999年12月31日。相反,SQL Server支持的日期从1753年1月1日到9999年12月31日。数据库的升级向导无法升级包含SQL Server不支持的日期的表格。这就意味着在升级之前你必须人工地处理这些日期。幸运的是,这一问题只影响少数的数据库。

与表格控制相关的查询
开发人员通常会使用表格控制的查询来限制或询问一个数据来源。一个表格可以提供将数据显示在一个特定报告中的多种选择。例如,SQL SELECT语句包含了用户的输入:

 SELECT Orders.RequiredDate, Orders.ShippedDate, Orders.Freight,
    Orders.ShipName, Orders.ShipAddress, Orders.OrderDate
FROM Orders
WHERE
 Orders.OrderDate Between [Forms]![DateFilter]![DateFrom] And [Forms]![DateFilter]![DateTo]));

为了限定报告中的数据,用户可以输入一个开始和结束的日期到列表(DateFrom 和DateTo)。其他的代码可以打开并显示满足用户输入的两个日期之间的记录。

因为这种查询方式被Jet处理,表格中产生的问题可以很快被解决。然而,当数据库升级时,SQL Server不会涉及到表格控制,结果通常为查询失败。为了修正这一查询方式,开发人员必须更改表格。我建议你使用输入参数属性,并将数值传递到SQL Server存储程序。

交叉表查询
SQL Server不支持Jet TRANSFORM语句──这一语句可以使一个交叉表查询成为可能。例如,数据库升级向导支持以下查询方式:

TRANSFORM Sum(CCur([Order Details].UnitPrice*[Quantity]*(1-[Discount])/100)*100)
    AS ProductAmount
SELECT Products.ProductName, Orders.CustomerID, Year([OrderDate]) AS OrderYear
FROM Products INNER JOIN (Orders INNER JOIN [Order Details]
ON Orders.OrderID = [Order Details].OrderID) ON Products.ProductID =
    [Order Details].ProductID
WHERE Orders.OrderDate Between #1/1/1997# And #12/31/1997#
GROUP BY Products.ProductName, Orders.CustomerID, Year([OrderDate])
PIVOT "Qtr " & DatePart("q",[OrderDate],1,0) In ("Qtr 1","Qtr 2","Qtr 3","Qtr 4")

 

还好,你无需在SQL Server中使用Transact-SQL (T-SQL) CASE关键词重新编写一个Access的交叉表查询。下面的SELECT语句描述了使用T-SQL方式重新建立一个交叉表查询的语法:

SELECT Customers.CustomerID, Customers.CustomerName
    SUM (Case When Orders.Orderdate BETWEEN '01-Jan-1990' AND '31-Dec-1996'
    Then [UnitPrice]*[Quantity] Else 0 End) as 1997)
FROM Customers INNER JOIN Orders
ON CustomerID=Orders.CustomerID

 

隐藏对象
所有的隐藏对象在数据库升级过程中都被忽略。对此,你最好的处理方法是使用程序对象的GetHiddenAttribute属性检查对象。例如,以下代码使用这一方法决定对象是否被隐藏。
Dim IsHidden As Boolean
If Application.GetHiddenAttribute(objtype, objname) Then  
  IsHidden = True
End If

如果特定的对象被隐藏,IsHidden布尔变量将被为True。

包含索引的表格
 
数据库升级向导不支持没有索引或其他限制的表格。升级向导可以升级一个无索引的表格,但其转换之后只能成为一个只读的表格。幸运的是,解决这一问题很简单:添加一个索引到每一个没有索引的表格。一旦你已经完成升级数据库,请记住将添加的索引删除。

数据库升级操作步骤
一旦你已经做好一切准备,并确定操作可以开始。数据库升级向导可以为你提供三种选择:

输出Access表格到SQL Server并链接到Access数据库

使用Pass-Through查询与SQL Server的后台服务器的表格相互通讯
将整个Access数据库移动到一个Access数据库工程(其只与SQL Server联系)
为了启动数据库升级向导,先从工具菜单栏中选择数据库功能,然后从子菜单中选择升级向导。向导的第一个面板提供两种选择:你可以建立一个新的SQL Server 数据库来存放Access表格,如图A所示,或者你可以在一个现成的SQL Server数据库中添加表格。选择一个现成的SQL Server数据库将需要输入一个数据服务名称(DSN)。

图 A

选择建立一个新的数据库或者使用一个现成的数据库
 
第二个面板要求获得SQL Server范例的信息。除此之外,你必须认证安全机制(如果存在)和为新的数据库提供一个缺省的名称,如图B所示。
图B
 

为一个新的数据库命名

在这点上,你可以将需要的表格复制到SQL Server,你也可以指出完成的部分将成为一个完整的ADP或者一个被链接的表格,如图C所示。

图 C

指明一个ADP或者一个被链接的表格


避开麻烦

每一个开发人员都有不同的数据库升级操作的经验,所以无法保证第一次操作就能够达到成功。然而,如果你遵循本文中提供的有关规则,你应该遇到更少的错误,即使碰到,你也可以很容易地修正错误,并继续操作。

本文作者:

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

MySQL vs. Other Databases: Comparing the Options MySQL vs. Other Databases: Comparing the Options Apr 15, 2025 am 12:08 AM

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

Using Dicr/Yii2-Google to integrate Google API in YII2 Using Dicr/Yii2-Google to integrate Google API in YII2 Apr 18, 2025 am 11:54 AM

VprocesserazrabotkiveB-enclosed, Мнепришлостольностьсясзадачейтерациигооглапидляпапакробоглесхетсigootrive. LEAVALLYSUMBALLANCEFRIABLANCEFAUMDOPTOMATIFICATION, ČtookazaLovnetakProsto, Kakaožidal.Posenesko

MySQL: Structured Data and Relational Databases MySQL: Structured Data and Relational Databases Apr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

How to solve nginx current limit How to solve nginx current limit Apr 14, 2025 pm 12:06 PM

The Nginx current limit problem can be solved by: use ngx_http_limit_req_module to limit the number of requests; use ngx_http_limit_conn_module to limit the number of connections; use third-party modules (ngx_http_limit_connections_module, ngx_http_limit_rate_module, ngx_http_access_module) to implement more current limit policies; use cloud services (Cloudflare, Google Cloud Rate Limiting, AWS WAF) to DD

Real-World MySQL: Examples and Use Cases Real-World MySQL: Examples and Use Cases Apr 14, 2025 am 12:15 AM

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.

MySQL: Key Features and Capabilities Explained MySQL: Key Features and Capabilities Explained Apr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

MySQL: A Beginner-Friendly Approach to Data Storage MySQL: A Beginner-Friendly Approach to Data Storage Apr 17, 2025 am 12:21 AM

MySQL is suitable for beginners because it is easy to use and powerful. 1.MySQL is a relational database, and uses SQL for CRUD operations. 2. It is simple to install and requires the root user password to be configured. 3. Use INSERT, UPDATE, DELETE, and SELECT to perform data operations. 4. ORDERBY, WHERE and JOIN can be used for complex queries. 5. Debugging requires checking the syntax and use EXPLAIN to analyze the query. 6. Optimization suggestions include using indexes, choosing the right data type and good programming habits.

See all articles