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

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

Jun 01, 2016 pm 02:05 PM
server sql upgrade database have Inquire sheet

Access

很多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

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

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

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

为一个新的数据库命名

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

图 C

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

指明一个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 Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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
1664
14
PHP Tutorial
1268
29
C# Tutorial
1248
24
Xiaoyi upgraded to an intelligent agent! HarmonyOS NEXT Hongmeng native intelligence opens a new AI era Xiaoyi upgraded to an intelligent agent! HarmonyOS NEXT Hongmeng native intelligence opens a new AI era Jun 22, 2024 am 01:56 AM

On June 21, Huawei Developer Conference 2024 (HDC2024) gathered again in Songshan Lake, Dongguan. At this conference, the most eye-catching thing is that HarmonyOSNEXT officially launched Beta for developers and pioneer users, and comprehensively demonstrated the three "king-breaking" innovative features of HarmonyOSNEXT in all scenarios, native intelligence and native security. HarmonyOSNEXT native intelligence: Opening a new AI era After abandoning the Android framework, HarmonyOSNEXT has become a truly independent operating system independent of Android and iOS, which can be called an unprecedented rebirth. Among its many new features, native intelligence is undoubtedly the new feature that can best bring users intuitive feelings and experience upgrades.

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

The best time to buy Huawei Mate 60 series, new AI elimination + image upgrade, and enjoy autumn promotions The best time to buy Huawei Mate 60 series, new AI elimination + image upgrade, and enjoy autumn promotions Aug 29, 2024 pm 03:33 PM

Since the Huawei Mate60 series went on sale last year, I personally have been using the Mate60Pro as my main phone. In nearly a year, Huawei Mate60Pro has undergone multiple OTA upgrades, and the overall experience has been significantly improved, giving people a feeling of being constantly new. For example, recently, the Huawei Mate60 series has once again received a major upgrade in imaging capabilities. The first is the new AI elimination function, which can intelligently eliminate passers-by and debris and automatically fill in the blank areas; secondly, the color accuracy and telephoto clarity of the main camera have been significantly upgraded. Considering that it is the back-to-school season, Huawei Mate60 series has also launched an autumn promotion: you can enjoy a discount of up to 800 yuan when purchasing the phone, and the starting price is as low as 4,999 yuan. Commonly used and often new products with great value

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

How to save JSON data to database in Golang? How to save JSON data to database in Golang? Jun 06, 2024 am 11:24 AM

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

See all articles