Tools for Migrating from Oracle to MySQL - sql

I want to migrate schema from Oracle to MySQl, so are there any free tools that would be useful for this task?
I have "Create table" statements in Oracle SQL Script, but it contains unique constraints and a foreign key. MySQL has MyISAM storage engine, and so foreign key is not supported.
How to solve this issue?
Sample Oracle create statements:
CREATE TABLE channels
(
obt_id NUMBER(19) PRIMARY KEY,
discriminator VARCHAR2(64) NOT NULL
CONSTRAINT check_channel_discriminator CHECK (discriminator IN ('CHANNEL','SALES_CHANNEL')),
chan_id VARCHAR2(255),
description VARCHAR2(255),
name VARCHAR2(255) NOT NULL,
obt_version VARCHAR2(255),
fk2_channel NUMBER(19)
CONSTRAINT fk_channel_channel REFERENCES channels(obt_id)
);
CREATE TABLE object_types
(
obt_id NUMBER(19) PRIMARY KEY,
enum_value VARCHAR2(64) NOT NULL,
external_name VARCHAR2(64) NOT NULL,
description VARCHAR2(255),
business_validation NUMBER(1) DEFAULT 0,
start_date_time DATE DEFAULT to_date('01011900','DDMMYYYY'),
end_date_time DATE DEFAULT to_date('01014712','DDMMYYYY'),
mut_date_time DATE DEFAULT SYSDATE,
mut_user VARCHAR2(32) DEFAULT USER,
CONSTRAINT object_types UNIQUE (external_name,start_date_time,end_date_time)
);

I have not heard of a single tool that can assist in what you are asking for. This does not mean one does not exist, however, it is probably easier and less error prone to take your existing Oracle scripts and manually create the appropriate MySQL scripts. On every project I have been on the DBAs were responsible for data migration of this type and they always did it manually.
Edit:
That being said I did a quick google search and there are a few programs that claim to do this (at a cost). For example:
Oracle to MySQL
Data loader
DBConvert
I would obviously caution against using a third party tool and make sure you back up everything before starting.

The mysql gui tool kit includes a migration tool.
http://dev.mysql.com/downloads/gui-tools/5.0.html
You'll need to have the jdbc driver for Oracle installed on the machine where your running the tool kit.

Related

Entity Framework Database First approach in Azure

I have a bunch of SQL scripts that create my database. I'd like to use the Database First approach with EF and Azure. I figured out that there are certain fields that my tables need to include:
CREATE TABLE dbo.Company
(
[Id] VARCHAR(50) NOT NULL CONSTRAINT DF_Company_Id DEFAULT '0',
CompanyName NVARCHAR(50) NOT NULL CONSTRAINT DF_Company_Name DEFAULT '',
-- Azure properties
[Version] TIMESTAMP NOT NULL,
[CreatedAt] DATETIMEOFFSET(7) NOT NULL,
[UpdatedAt] DATETIMEOFFSET(7) NULL,
[Deleted] BIT NOT NULL
)
I also figured out that I need certain constraints on these fields:
ALTER TABLE dbo.Company ADD CONSTRAINT PK_Company PRIMARY KEY NONCLUSTERED ([Id] ASC);
GO
ALTER TABLE dbo.Company ADD CONSTRAINT DF_Company_CreatedAt DEFAULT CONVERT(DATETIMEOFFSET(7), SYSUTCDATETIME(), 0) FOR [CreatedAt]
GO
ALTER TABLE dbo.Company ADD CONSTRAINT DF_Company_Deleted DEFAULT 0 FOR Deleted
GO
CREATE CLUSTERED INDEX IX_Company_CreatedAt ON dbo.Company([CreatedAt] ASC)
GO
CREATE TRIGGER [TR_Company_InsertUpdateDelete] ON dbo.Company
AFTER INSERT, UPDATE, DELETE AS
BEGIN
UPDATE dbo.Company
SET dbo.Company.[UpdatedAt] = CONVERT(DATETIMEOFFSET, SYSUTCDATETIME())
FROM INSERTED WHERE inserted.[Id] = dbo.Company.[Id]
END
GO
I'm wondering if there is any documentation for that. I'm not sure if I included all fields and constraints. Also, I'm not sure if creating tables using a SQL script like the above one is a good approach for EF with Azure.
Any advice?
===UPDATED TO CLARIFY THE QUESTION===
Maybe it would be clearer to explain my question step-by-step:
I have a bunch of SQL scripts that create database structure.
I'd like to make the database structure usable by Azure. For example, Azure has Offline Data Sync feature that I know requires certain fields in the tables.
Through trial and error, I have found that Azure uses certain fields (Version, CreatedAt, UpdatedAt, and Deleted) and triggers to provide its features (such as Offline Data Sync).
I modified my SQL scripts to include this "Azure-specific" fields and triggers.
The problem is the "trial and error" part. It's just wrong to apply such an approach in production code that potentially will be used by many users. I'd like to find out what exactly Azure needs in the database. When the database is created using Code First all the "plumbing" is created by Azure. With the Database First approach, I have to create this plumbing. I'm wondering if I did not miss anything.

Can't create graph tables with sqlproj

After getting really fed up with using hierarchyids to manage my node tree, I decided to take a stab at using SQL Server 2017's graph functionality to ease my troubles.
I have a little bit of confusion, though. Currently, all of my SQL scripts are stored and organized in a SQL database project. When I create a node table and publish it to my Azure SQL Database, it only creates a standard table.
However, I can paste the exact same query into SSMS and it creates the graph table just fine. I've included the query below. Am I missing anything obvious?
CREATE TABLE [dbo].[GraphSite]
(
[SiteId] UNIQUEIDENTIFIER NOT NULL DEFAULT NEWID(),
[SiteName] NVARCHAR(100) NOT NULL,
[SiteTypeId] UNIQUEIDENTIFIER NOT NULL,
[SiteTimeZone] NVARCHAR(20) NOT NULL DEFAULT N'America/New_York',
[SiteStatusId] UNIQUEIDENTIFIER NULL,
[SiteThemeId] UNIQUEIDENTIFIER NULL,
CONSTRAINT [PK_GraphSite] PRIMARY KEY ([SiteId]),
CONSTRAINT [FK_GraphSite_SiteType] FOREIGN KEY ([SiteTypeId]) REFERENCES [SiteType]([SiteTypeId]),
CONSTRAINT [FK_GraphSite_SiteStatus] FOREIGN KEY ([SiteStatusId]) REFERENCES [SiteStatus]([SiteStatusId]),
CONSTRAINT [FK_GraphSite_SiteTheme] FOREIGN KEY ([SiteThemeId]) REFERENCES [SiteTheme]([SiteThemeId])
) AS NODE;
EDIT: I installed SQL Server 2017 locally and it leaves "AS NODE;" in fine. So SSDT seems to have an issue building graph tables to Microsoft Azure SQL Database v12. Which is weird, considering Azure SQL databases fully support graph tables. Any thoughts?
Could you try downloading the latest version of SSDT from here: https://learn.microsoft.com/en-us/sql/ssdt/download-sql-server-data-tools-ssdt
This should fix the problem for you.

How to tell HSQLDB to allow identity definition for SERIAL?

I'm currently writing tests for a spring boot application which is using a postgreSQL database. During test I want to replace the database by some in-memory variant like H2 or HSQLDB. Sadly both do not behave the same as the postgreSQL database.
I have migrations that look like
CREATE TABLE foo(id BIGSERIAL PRIMARY KEY, ...)
This results in hsqldb telling me
SQL State : 42525
Error Code : -5525
Message : identity definition not allowed: FOO_ID
So apparently creating the matching sequence for the primary key is forbidden. Is there a way to tell hsqldb to accept this?
You need to set PostgreSQL compatibility mode in HSQLDB.
SET DATABASE SQL SYNTAX PGS TRUE
Your table definition is then accepted and converted internally to the SQL Standard equivalent.
CREATE TABLE FOO(ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY, ..

ROW_FORMAT=DYNAMIC sql query bug

this is the query :
CREATE TABLE `pedidos_detalle` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`fk_pedido` int(11) DEFAULT NULL,
`fk_articulo` int(11) DEFAULT NULL,
`precio` decimal(10,2) DEFAULT NULL,
`cantidad` int(11) DEFAULT NULL,
`importe` decimal(10,2) DEFAULT NULL,
`detalle` text,
PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=16503 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
The result of this query is the error message : #1005 - Can't create table 'netlogiq_acros.pedidos_detalle' (errno: 1478)
If i removed the ROW_FORMAT=DYNAMIC it works, but I know don't what will be the effects on the feature . Or if changed the InnoDB to MyISAM it also works. but still I do not know what will be effects. Can someone help me how to manage this ? explain me the differencet between myIsam and Innodb and for what reason I should use ROW_FORMAT=DYNAMIC or COMPRESSED ? thx
innoDB and MyIsam are Table formats. MyIsam is the older on and has been standard up until mysql 5.5. which version are you using? you can read about the advantages and disadvantages of both on wikipedia. i would recommend to use innoDB.
the meaning of the setting ROW_FORMAT = DYNAMIC is explained here: http://dev.mysql.com/doc/innodb-plugin/1.0/en/innodb-row-format-dynamic.html
but why would want this setting to be applied? as far as i understood, you do not know what ist exactly does? in this case i would prefer the working solution that i also do not understand over the not working solution that i still do not understand. Or do you have an external requirement?
I hope this helps.

How to set a primary key using SQL

I have this table 'Cars', attributes:
MODEL nvarchar(20)
STYLE nvarchar(20)
ENGINE nvarchar(5)
CAPACITY smallint
MAX_SPEED smallint
PRICE smallmoney
MARKET nvarchar(20)
COMPETITOR nvarchar(20)
I would like to set 'PRICE' as the primary key via a SQL sStatement, so I've tried:
ALTER TABLE Cars
ADD PRIMARY KEY (PRICE)
But I just get the error
The ALTER TABLE SQL construct or statement is not supported.
in Visual Studio 2010.
As has been said above, price is a bad primary key. But ... the correct syntax to do what you are trying to do is:
ALTER TABLE Cars
ADD CONSTRAINT cars_pk PRIMARY KEY (PRICE)
Visual studio is not a database client. If you want to run any query at all, you have to use a client that allows you to do so. The details depend on the database engine you are using.
If you want to do this with Visual Studio, you have to send that command, as a query, the same way you would send a select query. Once again, the details depend on your database engine.
Something else that depends on the database engine is the syntax of the command itself. Some will allow what you tried. Other will make you use the constraint keyword.
Finally, as mentioned in the comments, price is a poor choice for the primary key. Better choices would be a uuid, an autoincrementing integer, or, the VIN.