AWS Database Blog
Validate database objects after migrating from SAP ASE to Amazon RDS for SQL Server or Microsoft SQL Server
Migration of SAP ASE (previously known as Sybase ASE) to Amazon Relational Database Service (Amazon RDS) for SQL Server is heterogeneous in nature and consists of major phases such as pre-migration assessments, conversion of database schema, and post-migration validation. Because the migration process involves code conversion, it involves the crucial task of validating the converted database schema objects. The post-migration validation of database objects is an essential step that determines the success factor in the overall migration.
Because even a fully automated database migration process may involve manual conversion sometimes, there is always a chance of objects not getting converted wholly or a mismatch of key object features in the target database. This post is part of the series in which we have previously covered database object validation for migrations from SAP ASE as source to target databases like Amazon RDS for MySQL, Amazon RDS for MariaDB, MySQL or Amazon Aurora MySQL-Compatible Edition and Amazon RDS for PostgreSQL or Amazon Aurora PostgreSQL-Compatible Edition. In the final post of this series, we focus on how to validate the database schema objects migrated from SAP ASE to Amazon RDS for SQL Server with the help of SQL queries to avoid such shortfalls.
Amazon RDS for SQL Server is a preferred choice for modernizing SAP ASE workloads with minimal changes because both databases have Transact-SQL (T-SQL) as their database programming language and Tabular Data Stream (TDS) as their communication protocol.
Prerequisites
The following prerequisites are required to perform the post-migration validation provided in this post:
- An SAP ASE source database.
- An RDS for SQL Server target database post migration.
- An Amazon Elastic Compute Cloud (Amazon EC2) instance or a SQL client with necessary permissions to connect to both source and target databases and run the validation SQL queries.
- A database user with public access to the primary database on the source SAP ASE database. The user must have SELECT permissions on the following system tables:
[source_db].dbo.sysobjects
[source_db].dbo.syscolumns
[source_db].dbo.sysconstraints
[source_db].dbo.syspartitionkeys
[source_db].dbo.sysindexes
[source_db].dbo.sysreferences
[source_db].dbo.sysusers
master.dbo.spt_values
- Database user with necessary privileges used to create the database objects in the target database.
Database object validation
Performing schema validation should always be the first step after you convert the source schema objects from SAP ASE to their equivalent SQL Server schema objects. To perform these validations, we first need to understand the different types of database objects to consider for post-migration validation.
The following list contains the database objects that you can compare between SAP ASE and the corresponding SQL Server database. Validating these objects thoroughly reduces issues during later stages of database migration and ensures minimal impact for the applications working with the migrated data.
- Schemas
- Tables
- Views
- Functions
- Stored procedures
- Indexes
- Triggers
- Constraints
- Primary key constraints
- Foreign key constraints
- Check constraints
- Default constraints
In the following sections, we look into each of these object types and validate migration using their corresponding SQL queries to help us identify any mismatch in the migrated schema objects.
If you find differences for any of the schema objects, identify the reason of failure. Convert the objects to the target database equivalent manually and apply the converted code on the target database. You need to manually correct the SQL scripts to replace the target equivalent syntax of the database object before running them on the target database.
Note that we have excluded system schemas in the source and target databases. We cover both summary-level as well as detail-level validations depending on the database object type, and you can further modify these queries to include more attributes or aggregates as needed. Precede the SQL Server validation scripts with “USE <DB>” to query the specific database being validated.
Schemas
Schemas are used to represent a set of database objects that serve a related functionality in an application. In SAP ASE, there is default schema called dbo
, and if any user-defined schema is present, it’s the same as the user name of that specific user who is authorized to access objects in that schema. All database objects in SAP ASE have an owner; this object owner is effectively the same as a schema in SQL Server.
You can validate the schema at the source (SAP ASE) and target (SQL Server) using the following SQL queries.
Use the following SQL query for SAP ASE.
The following screenshot is an example of the SAP ASE output.
The following is a similar query for SQL Server.
You get the following output.
Verify if the schema results match between the source and target database using the preceding SQL queries. If any differences are found, identify the cause of failure from the deployment logs and fix them accordingly. In this example, we have an additional schema sap
created by the conversion tool along with the main schema dbo
. We have excluded the sap
schema in all other validation queries because it’s captured in this section.
Tables
In this section, we discuss tables under each schema (or owner) and detailed information for each table.
Tables under each schema
If you are using any migration tool for the conversion, it might convert source SAP ASE tables to the equivalent SQL Server target tables with appropriate data types and relative table definitions as per the target database syntax. To ensure that all the tables were migrated successfully, we can use the following script, which returns the schema and count of all the tables under it.
Use the following SQL query for SAP ASE.
You can see a sample output in the following screenshot.
The following is a similar query for SQL Server.
We get the following output.
Verify if the table count match between the source and target database using the preceding SQL queries. If any differences are found, identify the cause of failure from the deployment logs and fix them accordingly.
Detailed information for each table
Validating the count of the tables under the schema or object owner is not enough to conclude that all tables are migrated properly. The following SQL queries help in verifying a few key features of the tables involved in the migration, such as the presence of LOB columns, computed columns, partitions, and column count.
Use the following SQL query for SAP ASE.
The following screenshots show our output.
Additionally, you can check the locking scheme of your migrated SAP ASE tables to ensure the lock scheme remains the same post-migration as well.
The following is a similar query for SQL Server.
The following screenshots show the output.
Verify if the table details match between the source and target database using the preceding SQL queries. If any differences are found, it indicates the mismatch or missing of any of the features compared, identify the cause of failure using deployment logs and fix them accordingly.
Views
A view is a virtual table created by a query joining one or more tables. You can validate the views by using the following queries on the source and target databases.
Use the following SQL query for SAP ASE.
The following screenshot shows the sample output.
The following is a similar query for SQL Server.
We get the following output.
Verify if the views match between the source and target database using the preceding SQL queries. If any differences are found, identify the cause of failure using deployment logs and fix them accordingly.
Functions
Functions implement specific business logic based on the given input and return a predefined format of output. The following queries give you the details of functions for both the source and target databases.
Use the following SQL query for SAP ASE.
The following screenshot shows our output.
The following is a SQL query for SQL Server.
The following screenshot shows the query output.
Verify if the function results match between the source and target database using the preceding SQL queries. If any differences are found, identify the cause of failure from the deployment logs and fix them accordingly.
Stored procedures
A stored procedure is a collection of pre-compiled SQL statements stored in a database memory for quick access from an application program. Stored procedures have better performance compared to inline queries because the SQL queries are pre-compiled with reusable run plans. It also improves productivity because similar SQL statements or the business logic are consolidated and reused across applications or other programs. The following queries give you the count and details of stored procedures for both the source and target databases.
Use the following SQL query for SAP ASE.
You get the following output.
The following is a similar query for SQL Server.
The output is as follows.
Verify if the procedure information match between the source and target database using the preceding SQL queries. If any differences are found, identify the cause of failure from the deployment logs and fix them accordingly.
Indexes
Indexes in the database system play an important role in overall system performance. Although indexes can improve performance of read operations, it hinders write operations. Choosing the right indexing strategy is the key. There are several types of indexes available; the number of indexes and their type may differ from SAP ASE to SQL Server based on your use case.
With the following queries, you can get the list of indexes and their types in both SAP ASE and SQL Server databases.
Primary keys are not included in the following SQL query; we discuss them in a later section.
Use the following SQL query for SAP ASE.
The following screenshots show the output.
You can use the following SQL query to fetch index information for SQL Server.
The following screenshots show our output.
Verify if the index details match between the source and target database using the preceding SQL queries. If any differences are found, identify the cause of failure from the deployment logs and fix them accordingly.
Triggers
Triggers define a set of actions that are performed in response to an insert, update, or delete operation on a specified table. The following queries give you the details of triggers for both the SAP ASE and SQL Server databases.
Use the following SQL query for SAP ASE.
You get the following output.
Use the following SQL query for SQL Server database.
You get the following output.
Verify if the trigger details match between the source and target database using the preceding SQL queries. If any differences are found, identify the cause of failure from the deployment logs and fix them accordingly.
Constraints
Constraints offer the advantages of defining integrity controls in one step during the table creation process and simplifying the creation of those integrity controls. However, integrity constraints are more limited in scope and less comprehensive than defaults, indexes, and triggers.
Primary key constraint
Use the following SQL query for SAP ASE.
You get the following output.
Use the following SQL query for SQL Server database.
The following screenshot shows the output.
Foreign key constraint
Use the following SQL query for SAP ASE.
You get the following output.
Use a similar SQL query for SQL Server database.
You get the following output.
Check constraint
Use the following SQL query to get a summary of check constraints on the SAP ASE database.
You get the following output.
Use a similar query for SQL Server.
You get the following output.
Default constraint
Use the following SQL query for SAP ASE.
You get the following output.
Use a similar query for SQL Server.
You get the following output.
Verify if the constraint details match between the source and target database using the preceding SQL queries. If any differences are found, identify the cause of failure from the deployment logs and fix them accordingly.
Conclusion
In this post, we discussed validation of different database objects with queries for SAP ASE and SQL Server database. These queries work for SAP ASE 15.7+ and SQL Server 2019. You can use this post as a reference guide for related database object validation to help you plan your database migration journey.
Database migration should always be followed by testing, including unit testing, functional testing, and regression testing for all the objects irrespective of automatic or manual migration. This saves a lot of reworking when you conduct integration testing with your applications or interface.
If you have any comments or questions, leave them in the comments section.
About the authors
Pavithra Balasubramanian is a Database Consultant with Amazon Web Services in India. She is passionate about helping customers in their cloud adoption journey with a focus on legacy database migrations to AWS cloud.
Nishad Mankar is a Database Consultant with AWS Professional Services. He helps customers to migrate and modernize their databases on AWS Cloud.
Amit Kumar is a Database Consultant with AWS Professional Services based out of Hyderabad, India. With good knowledge on relational databases adding hands-on in homogenous and heterogenous database migrations and optimization in AWS cloud.