Load Data From Linked Server to Another Linked Server - sql-server

I have an Integration Server where I have defined linked servers of my sources (SQL Server database) and target database (Azure SQL DW). I have conditions where if the table does not exist I will use a SELECT INTO, then use an INSERT INTO when the table already exists.
My code is as follows:
SELECT *
INTO [tgt_svr].[tgt_db].[tgt_sch].[tgt_tbl]
FROM [tgt_svr].[tgt_db].[tgt_sch].[tgt_tbl];
INSERT INTO [tgt_svr].[tgt_db].[tgt_sch].[tgt_tbl]
SELECT *
FROM [tgt_svr].[tgt_db].[tgt_sch].[tgt_tbl];
However when I execute I get this error
... contains more than the maximum number of prefixes. The maximum is 2.
Appreciate any help how to resolve this and achieve my result to have this processing server extract from source server and load to target server.
Thank you!

Related

SQL Server select from linked server throw error if user has "deny view definition"

I have users with datareader permission on my sql, the problem is that i noticed that the users are doing "fishing" query a lot (they don't know what exactly should be querying to get what thy need).
This is a production SQL and we started to have deadlock because of those users.
Trying to don't break their process i applied "deny view definition to [user]" so they cannot see the list of tables, view, stored procedure, so no more "fishing"
This was a great solution, it works perfect if you connect directly to the SQL Server, you can run queries (select) but you cannot see the list of tables.
However many users are using those account to connect to our SQL using linked server, and when the run a query using the linked server they are getting error:
SELECT TOP 100 *
FROM [SERVERSQL].[DATABASE].dbo.[TABLE]
Msg 7314, Level 16, State 1, Line 1
The OLE DB provider "SQLNCLI11" for linked server "SERVERSQL" does not contain the table ""[DATABASE]"."dbo"."[TABLE]"". The table either does not exist or the current user does not have permissions on that table.
Using SQL Server version 2014 (v12.0.2000.8) and 2016 (v13.0.5492.2).
What is the correct way to hide tables, view, stored procedures, etc but allow select and make it work on linked server?
Thanks
Linked server from one SQL Server to Another:
Linked server name is: PLWNSAVSQL02D which is SQL Server
This sql to linked server works:
select count(*) from [PLWNSAVSQL02D].[SFI_WMS].dbo.[TCOMPANYPALLETMESSAGES];

How to copy data from a view of one server into the database table of another server in a SQL server database?

how can i copy data from a view of one server into the database table of another server in a SQL server database without using linked servers method.
I tried using the code:
SELECT [LogEntryID]
,[TimeStamp]
Into [server-2].[database1].[dbo].[table1]
FROM [server-1].[database1].[dbo].[view_1]
I recieve the error " The object name 'server-2.database1.dbo.table1' contains more than the maximum number of prefixes. The maximum is 2.
The copying statement i am using in a groovy code. But for first i am trying it in a query if it works.
You can use opendatasource instead of linked server
insert DestinationTable
select * from opendatasource('SQLOLEDB', 'Server=SourceServer;User Id=Username;Password=Password;').SourceDb.Schema.SourceTable;
OPENDATASOURCE

Cannot create trigger on linked server in SQL Server

I have one local database in SQL Server and one Oracle database as an linked server in SQL Server. I want to create a trigger on the linked server (Oracle database table) which will insert data into SQL Server table. This is what I have tried
CREATE TRIGGER TrgItemInsert
ON ORACLEDB..SYSTEM.ITEM
AFTER INSERT
AS
BEGIN
PRINT 'Something Happened to Table ITEM'
END
but I get the following error:
The object name 'ORACLEDB..SYSTEM.ITEM' contains more than the maximum number of prefixes. The maximum is 2.
Is this possible?
Is there any work around to achieve this task?
Connection to the linked server is working and I can query the data in the linked server using 'SELECT' statements.
Thanks in advance.

Linked server working with three dot notation, but not with 4 part name in SQL Server?

Linked server working with three dot notation, but not with 4 part name in SQL Server.
For example: when I run
SELECT top 1 *
FROM [POSTGREFGH]...DEPARTMENT
I am getting results, but when I try this:
SELECT top 1 *
FROM [POSTGREFGH].MyDB.[MyShema].DEPARTMENT
I get this error:
Invalid use of schema or catalog for OLE DB provider "MSDASQL" for
linked server "POSTGREFGH". A four-part name was supplied, but the
provider does not expose the necessary interfaces to use a catalog or
schema.
My source server is : POSTGRESQL
Where and what was wrong with this?
Thanks in advance

Transfering Data From Production Server To Development Server

I am want to make the following statement:
INSERT INTO [Server_1\Instance_1].[Database].[dse].Table1
SELECT * FROM [Server_2\Instance_2].[Database].[dse].[**Table1**]
The point is the tables are on the different servers. I tried with the statement above. However, when I am on server_1 and when I run the following statement in order to retrieve the data from server 2:
SELECT * FROM [Server_2\Instance_2].[Database].[dse].[**Table1**]
... I get zero rows.
But when I run the statement above on the Server_2, I get a set of rows.
How can I transfer data from production to development server/environments?
I am using MS Management Studio.
UPDATE:
The error message I am getting when I run the select statement in order to retrieve the data from another (production) server:
The OLE DB provider "SQLNCLI10" for linked server "Prod_Server\Instance" does not contain the table ""Database"."dse"."BoxIteration"". The table either does not exist or the current user does not have permissions on that table.
Select statement is:
SELECT * FROM [Prod_Server\Instance].[Database].[dse].[BoxIteration]
Two things to take into account:
add the source server as a linked server in the destination server
verify that the credentials specified while creating the linked server have access to the data in the source server
I have a localized version of SQL Server, so the transalation may not match what you will see in your screen: open Object Explorer window in SSMS, connect to the destination server, open the tree and look for Server Objects, Linked Servers. Right click on the source linked server, and see the properties. Open the Security pane, and see which credentials are used to connect to the linked server.
Once you do so, you have to check the permissions of that credentials on the source server to verify that it can acccess the table in question.
If you don't understand, or can't do some of the steps (for lack of permissions), get help form your DBA: he will understand and solve the problem at once.
If u have access(Having credentials) to both prod and dev Db servers you can use "Import and Export Data"
1.Go to start and open "Import and Export Data"
Wizard will open give source server name, credentials and Database(For your case Prod)
Then give destination server name, credentials and Database(Dev)
Select the table , if there any identity column -->"Edit Mapping" and Enable identity insert.
Then give next--> it will start copying.

Resources