SQL Server 2005/8 allows you to associate a synonym with a remote table (i.e. a table on a different instance - the reference is via a 4-part name, which includes the link server name). Does anyone know whether SQL Server 2012 allows a synonym to be directly associated to the Link Server name (rather than a table which exists on the target)
Looking at the Books Online for SQL Server Denali, there appears to be no change in syntax or usage for SYNONYM's. Probably a safe bet to assume there will be no difference.
Why don't you just duplicate the linked server with your desired new name?
That's not a synonym, but the same server will be available with two names, so in practice they are pretty much the same.
Related
I am a SQL Server database developer. We have a current requirement that we need to link our product with an existing application of a client. Our product has a SQL Server 2012 database while the client's existing application uses Oracle 11g. Since the time limit for the project completion is limited we cannot migrate our application to Oracle.
The requirement is that we have to get the customer details from the Oracle database to do billing activities in our system.
So I went through a few links and found that SQL Server linked server can be used to do this. I have successfully created a view which uses the Customer table from the Oracle database using a linked server. It will solve our problem.
Now here are my questions:
Is there any better solutions to do this other than linked server?
Are there any drawbacks when using linked server for this?
Thanks in advance
One drawback to consider is that the filtering on your view may take place at "your" end, rather than in Oracle. e.g. if you have a linked server (using, say, an OPENQUERY statement) and a view based on that and you do this:
select id from myView where id = 4711
expecting that the result will be very quick (assuming id is indexed etc.etc.), then you may be in for a shock as what will actually happen is:
the entire contents of the Oracle table are passed to SQL Server
SQL Server then filters this data, i.e. the filtering cannot be "pushed
down" into the view objects (as they are remote).
N.B.: I know there are two ways to define linked server (openquery and the other one, I forget the details), so this may not always apply, but you should be aware of the potential performance hit.
I am new to MS SQL and I am trying to do something that seems simple but is driving me crazy.
I want to write a query to pull data from two databases. Each database is on a different instance on the same DEV machine. (one is MS SQL 2008 and the other MS SQL 2005). I am using the Microsoft SQL Server Management Studio (MSSMS).
I have the basics figured out. I know the format of the query and what I need to do. My big problem is figuring out what the NAME of each server is?
SELECT LastName
FROM [servername1].CHA2.dbo.Customer
UNION
SELECT LastName
FROM [servername2].OBXKites.dbo.Contact
ORDER BY LastName
I used the server name that I connect to MSSMS (DLPT\HENRY) with and what is also returned by ##SERVERNAME
SELECT ##SERVERNAME returns DLPT\HENRY
I tried
DLPT\HENRY.CHA2.dbo.Customer
did not work
I tried it without the DLPT HENRY.CHA2.dbo.Customer
did not work
I need to future out what the NAME of the server is to use in the query.
[DLPT\HENRY].CHA2.dbo.Customer
The namo contains a backslash which is normally illegal in an identifier. You surround illegal names with brackets.
Note that you surround just the server name. In other words, it is [DLPT\HENRY].CHA2.dbo.Customer, not [DLPT\HENRY.CHA2.dbo.Customer].
You have to configure Linked servers. Then only different instances of SQL Server are able to communicate with each other.
Unfortunately you can't access tables in databases in separate SQL Server instances by default. You have a couple of options here - neither are simple and might require help from a DBA:
1) Use linked servers like this:
http://technet.microsoft.com/en-us/library/ff772782(v=sql.110).aspx
Then you will be able to refer to the second table in the format INSTANCENAME.DatabaseName.SchemaName.TableName
2) Use replication to get the table from the second database into the first database. Then the contents of the second table will be synched to the first database in more or less real time
Read about SQL Replication here
I have a two big programs that connect to a SQL Server 2005 database.
Now we will migrate to a new server with SQL Server 2008.. the programs don't work anymore when connected to the new server, the cause is that in all the queries in the programs only table names are used, and they are not dbo tables.. so SQL Server 2008 doesn't recognise them, unless I use the schema name before the table name...
It is very very difficult for me to change all the queries in the two programs to add the schema name before the tables names.
I read in this forum that if I specify the default schema the problem will be solved.. but it haven't been solved though.
The only solution that seems to be working is when I changed the schema of the table to dbo.. but I am not sure if this action will be OK or will it cause some other problems related to this modification?
Is there any better solution?
Will changing the schema of the tables cause me other kind of problems?
Many thanks in advance
Default schemea will work for you. What are the issue with this approach?
Change schema name will cause a big issue and not advisable. Where and how much schema name change?(just think).
You just set a default schema with only one procedure first and check, if this is ok. then change the whole database schema.
https://dba.stackexchange.com/questions/21158/net-sql-server-authentication-schema-issue
In sql server 2005, how do I change the "schema" of a table without losing any data?
Change Schema Name Of Table In SQL
Best practice for SQL Server 2008 schema change
Subquestioning [1] and [2].
Where does SQL Server store server objects?
And why there?
Update:
This question is defined as subquestion and in context of cited questions...
Should I understand the answer that sql_policy_trigger, shown under Server Objects\Triggers in Object Explorer of SSMS (MS SQL Server R2), is stored in master database?
=====Update2:
Please give me the references to msdn docs in your answer(s).
It is not obvious that system or server configuration objects, meta-information or catalogs are stored in database(s). For ex., FTS catalog is not stored in database but in file (system), etc.
[3] (BOL2005-2008R2) tells that:
"master Database
Records all the system-level information for an instance of SQL Server"
"In SQL Server, system objects are no longer stored in the master database; instead, they are stored in the Resource database"
So, it is instance-wide (but not server-wide) and it clearly mentions "system".
As well as it hints that "they" are not stored in master database.
Also, I would like to understand why SSMS permits to script server objects (for ex., right-click in Object Explorer under Server Objects --> Triggers on syspolicy_server_trigger --> Script Server Trigger as...---> ) while, for ex., system views do not have such possibility.
Cited:
[1]
Where does a Server trigger save in SQL Server ?
Where does a Server trigger save in SQL Server?
[2]
“system objects” vs. “server objects” in SQL Server - terms definitions?
"system objects" vs. "server objects" in SQL Server - terms definitions?
[3]
master Database
[3a]
(SQL Server 2008 R2 Books Online)
http://msdn.microsoft.com/en-us/library/ms187837.aspx
[3b]
(SQL Server 2005 Books Online)
http://msdn.microsoft.com/en-us/library/ms187837(v=SQL.90).aspx
sys.objects, sys.indexes etc (as per your trigger question). See Object catalog views in MSDN
As for why, a relational database may as well use a relation structure to store information about itself, no? Apart from a few registry settings used on start up, almost every setting and object is stored in a table somewhere in SQL Server.
Examples:
sys.messages = error messages
sys.configurations = sp_configure
Edit, I had to dredge my memory about why this is so...
Rule zero in Codd's law
The system must qualify as
relational, as a database, and as a
management system. For a system to
qualify as a relational database
management system (RDBMS), that system
must use its relational facilities
(exclusively) to manage the database.
This ignores the "relational" puritans and zealots but explains why sys.objects etc are used.
Edit:
Making a guess at what OP really wants... server level objects are stored in the master database.
I've tried the obvious:
USE linkedServerName.databaseName
Which gives me the error:
`Could not locate entry in sysdatabases for database 'linkedServerName'.
If something like this were possible, it'd save me a bunch of clicking around in management studio!
Linked server definitions are designed for use as part of the four-part naming convention:
[LinkedServerDefinition.][DatabaseName.][SchemaName.]DatabaseObject
for example, OtherServer.Database.dbo.MyTable
They might have other uses, but with the USE statement is not one of them.
Would
SELECT * from LinkedServerDefinition.master.sys.databases
help in identifying what databases are "over ther"?