Azure SQL Data Migration Assistant (DMA) Error - Three or Four Part Names - sql

I'm using the MS Data Migration Assistant tool to move a SQL Server 2016 DB to Azure. I'm getting the following error on 80+ stored procedures:
Queries or references using three- or four-part names not supported in Azure SQL Database. Three-part name format, [database_name].[schema_name].[object_name], is supported only when the database_name is the current database or the database_name is tempdb and the object_name starts with #.
All of these stored procedures are using the current database and referencing the current database name. For example, this instruction is causing the error:
DELETE FROM [STDR].[dbo].[report] WHERE [report_id] = #xid
and when I run the command:
SELECT DB_NAME();
I get:
STDR
Could this be an error in the DMA tool? It's preventing me from executing the migration. I'd rather not have to modify all of these procedures. Thanks.

1.Queries or references using three- or four-part names not supported in Azure SQL Database.
It's not the error in the DMA tool. Cross database queries using three or four part names is not supported in Azure SQL Server.
You can read more in the official documentation:Resolving Transact-SQL differences during migration to SQL Database。
2.Three-part name format, [database_name].[schema_name].[object_name], is supported only when the database_name is the current database or the database_name is tempdb and the object_name starts with #.
About this question, I have an idea and I think you can try it. You can specify target Azure Database instance which has the same database name and the same schema objects with your on-premises SQL Server. Otherwise, when your SQL Server 2016 DB is migrated to Azure, the current database is not [STDR] and cause the error.
Reference: Migrate on-premises SQL Server or SQL Server on Azure VMs to Azure SQL Database using the Data Migration Assistant.
Hope this helps.

It's just the four-part name or three-part name that is not compatible with Azure SQL Database. You can script all your programing objects and then change the three part name format to two-part name format (dbo.[NameOfTheObjet]) on the script using Find and Replace on a text editor like Notepad++, then run that script on your Azure SQL Database to migrate your programming objects.
After that you can use DMA only to migrate the schema and data of your tables.

Related

How to copy one table data to another one between two Azure databases on the same server

I want to copy data from one database table into another database table on the same server in Azure SQL. I have done all of the Azure SQL Cross Database Query' steps that are written here https://www.mssqltips.com/sqlservertip/6445/azure-sql-cross-database-query/but still get the same error whenever I execute a query
'Reference to database and/or server name in 'db name' is not supported in this version of SQL Server.'
Can you pls help to figure out this?
Azure SQL database doesn't support across query directly.
We can not use USE statements and it not supported. That's why you get the error. We can not run statements like select * from [other_database].[schema].[table].
In Azure SQL database, only elastic query overview (preview) can achieve cross database query:
The elastic query feature (in preview) enables you to run a
Transact-SQL query that spans multiple databases in Azure SQL
Database. It allows you to perform cross-database queries to access
remote tables, and to connect Microsoft and third-party tools (Excel,
Power BI, Tableau, etc.) to query across data tiers with multiple
databases.
You could follow the tutorial and it may be more complex than on-premise SQL Server:
Get started with cross-database queries (vertical partitioning) (preview)

select values ​from database to another with sql server

Hello I have to pass a select from a database that is on an ip address to another (identical) database that is on a completely different IP, below the query how to pass to make the switch?
Sql Code:
/*Insert into database with same name into same table addres:: 172.16.50.98*/
Insert into
/* select from database address: 172.16.50.96*/
SELECT IdUtente,Longitudine,Latitudine,Stato,DataCreazione
FROM Quote.dbo.Marcatura
where DataCreazione>'2019-01-08 18:37:28.773'
Linked Server/ OpenQuery is the way to achieve this. have a look on this.
including parameters in OPENQUERY
If the data that's being imported isn't large and this won't be a reoccurring task a linked server would probably be the better option. Creating one through the SSMS GUI is easier if you haven't done this before, but an example of creating one using the SP_ADDLINKEDSERVER stored procedure through T-SQL is below. If your account doesn't have access to the other server the SP_ADDLINKEDSRVLOGIN stored procedure will need to be used to configure the linked server with an account that has the appropriate permissions on the source server, as well as database and any referenced objects. While using the linked server syntax (4 part name) is simpler and easier to read, I'd strongly recommend doing the insert with OPENQUERY instead if only one linked server will be used. This will execute the SQL on the source server, applying any filters there and only return the necessary rows, whereas the linked server syntax will return all the rows before performing the filtering. You can read more about the differences between the two here. You indicated the database name is the same on both servers, and this assumes the same for the table and schema names as well. Make sure to update these accordingly if they differ.
If a large volume of the data will imported or if this will be a regular process creating an SSIS package and setting this to run as a SQL Agent job will be the better approach. If you choose to go this route there are a number of things to consider, but the links below will help you get started. SQL Server Data Tools (SSDT) is where the packages can be developed. While not necessary, executing the packages from the SSIS Catalog, SSISDB, will be much more beneficial than just the using the file system. Either an OLE DB or SQL Server Destination can be used since the table that's being loaded to is on SQL Server, however a SQL Server Destination can only be used on a local database.
Linked Server:
--Create linked server
--SQL product name and SQLNCLI11 provider for SQL Server
EXEC [MASTER].DBO.SP_ADDLINKEDSERVER #server = N'MyLinkedServer', #srvproduct=N'SQL',
#provider=N'SQLNCLI11', #datasrc=N'ServerIPAddress'
--OPENQUERY insert
INSERT INTO Quote.dbo.Marcatura (IdUtente, Longitudine, Latitudine, Stato, DataCreazione)
SELECT
IdUtente,
Longitudine,
Latitudine,
Stato,
DataCreazione
FROM OPENQUERY(MyLinkedServer, '
SELECT
IdUtente,
Longitudine,
Latitudine,
Stato,
DataCreazione
FROM Quote.dbo.Marcatura')
SSIS:
SSIS
SSDT
SSISDB
Execute SQL Task
Data Flow Task
OLE DB Source
OLE DB Destination
SQL Server Destination
SQL Server Agent SSIS Packages
SSIS solution
I think this requires a very simple SSIS package to be achieved:
Create two OLEDB Connection manager; one for each server
Add a data flow task
Inside the Data flow task addan OLEDB Source and OLEDB destination
In the OLEDB source (172.16.50.98 connection manager) select SQL command as Access mode and use the following command:
SELECT IdUtente,Longitudine,Latitudine,Stato,DataCreazione
FROM Quote.dbo.Marcatura
where DataCreazione >'2019-01-08 18:37:28.773'
Map the source columns to the OLEDB destination (172.16.50.96 connection manager)
Helpful links
Extract Data by Using the OLE DB Source
SSIS OLEDB Source to OLE DB Destination example

Calling functions of master DB from other DB on the same Azure SQL Server

I have Azure SQL DB Server + one Azure SQL database on it. Within this DB I have functions which call some functions of master DB as a part of their logic.
Example:
CREATE FUNCTION [dbo].[EncryptByKey]
(
#EncryptionKeyId nvarchar(1024),
#ValueToEncrypt varchar(MAX)
)
RETURNS VARCHAR(MAX)
AS
BEGIN
RETURN master.dbo.fn_varbintohexstr(ENCRYPTBYKEY(Key_GUID(#EncryptionKeyId), #ValueToEncrypt))
END
Gives me an error:
Cannot find either column "master" or the user-defined function or
aggregate "master.dbo.fn_varbintohexstr", or the name is ambiguous.
If instead I try:
exec master.dbo.fn_varbintohexstr(123)
The error I get is:
Reference to database and/or server name in
'master.dbo.fn_varbintohexstr' is not supported in this version of SQL
Server.
Are there any solutions on how to use master DB functions from user's DBs on Azure SQL server?
You cannot use distributed database queries using three or four part names on SQL Azure.
For queries that span multiple databases in SQL Azure, you need to use elastic queries. For more information, please visit this article.

SQL Server Compact Edition - Obtain create script

I normally live in a MySQL world where I can use the
SHOW CREATE TABLE <tablename>
syntax to get the create script of a given table.
I'm working with a legacy SQL Server CE 3.5 database and need to get the create script for all of the tables so I can move them into another database which will be created by my application.
Is there any equivalent to the MySQL functionality that would allow me to do this?
YOu can use my free tool to to script object creation and data statements from a SQL Compact database - http://sqlcetoolbox.codeplex.com

How to compare the data between two query results from SQL Server and DB2

As part of a migration project I need to test the data in the source database (in SQL Server) with the target database (in DB2).
Some of the columns from the source are mapped to the target tables. The source database has millions of rows and I need to confirm the data is properly migrated.
How can I compare the data resulting from SQL queries on both the source and target databases?
Please provide some solution.
In MS SQL Server you can link to DB2 using the Linked Server feature, then you can execute some queries against both servers or even joining them in a same query. Be aware of the cost (network, disks, memory...). You will have to perform some performance tests.
See how to link the servers:
Creating a linked server to DB2 using Microsoft OLE DB provider for DB2
As #Caffe said, you can link both databases. From DB2 you can do that by Federation. However, this option is not included in the basic installation, and you should use Information Integration (that is not the last name, it changed recently).