简体   繁体   中英

SQL Importing Microsoft Access sql dump to Postgres

I have a Microsoft Access SQL dump which I am trying to import using psql -f option but getting errors while importing. So is there a way I can convert this SQL dump to support Postgres format.

I have seen some tools which can covert mdb files to respective tables but they are not retaining relationships and other constrains which existing dump has and I want to retain in the import.

# psql -U postgres -f test.sql
psql:test.sql:63: invalid command \Administrators]
psql:test.sql:570: ERROR:  syntax error at or near "Use"
LINE 1: Use [master]
        ^

The dump contains something like below

Use [master]
 GO
 EXEC dbo.sp_dbcmptlevel @dbname=N'test', @new_cmptlevel=90
 GO
 IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
 begin
 EXEC [test].[dbo].[sp_fulltext_database] @action = 'enable'
 end
 GO
 ALTER DATABASE [test] SET ANSI_NULL_DEFAULT OFF

 . . . .


 IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ClassOfService_PBX]') AND parent_object_id = OBJECT_ID(N'[dbo].[ClassOfService]'))
ALTER TABLE [dbo].[ClassOfService]  WITH CHECK ADD  CONSTRAINT [FK_ClassOfService_PBX] FOREIGN KEY([PBX])
REFERENCES [dbo].[PBX] ([ID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
. . . 

So is there a way I can import the data.

You will want to load the dump back into MS Access, then use tools to extract the data from the live MS Access over ODBC or similar. Milen already pointed out that several are listed on the PostgreSQL wiki . There are also generic ETL tools like Talend Studio, Pentaho Kettle, and CloverETL for data migration.

If you can only work with a dump, you'll probably have to convert the syntax by hand.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM