Query Syntax for linked sql server - sql

please help: I'm new to linked servers & in MS SQL I have successfully added one (from an MS Access file) as shown:
I'm having trouble querying this database here. What is the syntax? Thanks.

Okay, by simply using Management Studio in MS SQL I ran a SELECT query on the table through "Script Table as" (right-click) and with query results I was sure that this then is the format:
SELECT * FROM [RXPIPEDB]...[product]
Furthermore, I can run updates using this syntax:
UPDATE [RXPIPEDB]...[Product]
SET X = ..something..
Of-course for the UPDATE query, you must have set your LINKED SERVER properties > Server Options "RPC" & "RPC out" to TRUE.
Thank you all.

The query its OK. U have a problem in the configuration of linked server.
Check this: Run a Query from Linked Server (Oracle) in SQL Server2008 R2

Related

SQL Server 2012 using codes instead of design (TSQL)

I am using SQL Server Management Studio 2012 and I want to create tables using SQL codes(TSQL) instead of designing the table, I saw tutorial on how to do this but when I try to open the file of the table it gives me this message:
I solve it, its very simple all I needed to do is right click the file it choose select top 200 and it will open tsql.

How do you pull data from a database to another one using a linked server?

I have a local server set up on my computer with a local database. I am trying to connect to a network server with a linked server (I'm having a lot of trouble with this) and then create tables and views in the local database from the data in the network database. I'm using Microsoft SQL Server Management Studio 2012.
Try something like :
SELECT * from openquery(LINKED_SERVER_NAME,'SELECT * FROM TABLE')
If your linked server is well configured, you should be able to query the tables in the linked server using openquery.
Try this. First you link the Server then run query against the linked Server.
EXEC Sp_addlinkedserver
#server="MY-PC\SQLServer1",
#srvproduct='SQL Server'
-- from SQL Server2 you run this query
SELECT *
FROM Openquery("my-pc\sqlserver1", 'select * from Students')
Reference: Running Query against linked Server
SELECT * FROM [LINKEDSERVERNAME].[DATABASENAME].[DBO].[TABLENAME]

Can I create a view that will query a table from another sql server on another server but same domain

I need to query a table from another SQL Server on a different server but same domain, but I am not sure how I will be able to do it.
I tried solution given in this answer Can I create view in my database server from another database server but it doesn't work for me as I got SQL Server 2000 (please don't hate :-) ).
When I try solution given then i get this error,
Line 23: Incorrect syntax near '-'.
which is because command is not compatible with SQL Server 2000.
Edit
SELECT * FROM AnotherServer.AnotherServerDatabase.Server.Table1
you can link the servers and run cross server queries as long as you put the server name before the DB your running the query on.
For example
SELECT * FROM "linkedserver".dbo.aTable
(without "" marks )
bear in mind different server versions though. I run cross server queries from 2008 to 2000 servers and its a pain adapting :)

How to use two servers in one sql statement?

So I need to try and use two different servers in one SQL statement. Here is my query so far:
SELECT p.FirstField
from [FirstDatabase]..FirstTableName p
Where not exists (select p2.SecondField
from [SecondServer].[SecondDatabase]..SecondTableName p2
where p.FirstField = p2.SecondField)
I do not use the First Server in the first part of the statement because that Server has already been selected.
I am using Microsoft SQL Server
You need to set up the remote server as a linked server using sp_addlinkedserver. Then you can refer to the remote table using the linked_server_name.catalog.schema.object_name syntax. You can find more information here.

How can I write a message to SQL profiler from Sql a query?

I am troubleshooting for some SQL issue and I use SQL Profiler in order to diagnose some problem.
Is it possible to write some messages into SQL Profiler by adding some lines in a TSQL query?
thanks!
you can do by adding comment to your t-sql
like
-- My message
select * from table1
and send all to sql
The Application Name should also be different. For our installation, activity on the website gives an application name of ".Net SqlClient Data Provider", while queries from SQL Server Management Studio are designated as... well... "SQL Server Management Studio"