Adding a Linked server can be done
by either using the GUI interface or the sp_addlinkedserver
command.
Adding
a linked Server using the GUI
There are two ways to add another
SQL Server as a linked server. Using the first method, you need to
specify the actual server name as the “linked server name”. What this
means is that everytime you want to reference the linked server in code, you
will use the remote server’s name. This may not be beneficial because if
the linked server’s name changes, then you will have to also change all the
code that references the linked server. I like to avoid this method even
though it is easier to initially setup. The rest of the steps will guide
you through setting up a linked server with a custom name:
To add a linked server using SSMS
(SQL Server Management Studio), open the server you want to create a link from
in object explorer.
- In SSMS, Expand Server Objects -> Linked Servers -> (Right click on the Linked Server Folder and select “New Linked Server”)
Add New
Linked Server
- The “New Linked Server” Dialog appears. (see below).
Linked
Server Settings
- For “Server Type” make sure “Other Data Source” is selected. (The SQL Server option will force you to specify the literal SQL Server Name)
- Type in a friendly name that describes your linked server (without spaces). I use AccountingServer.
- Provider – Select “Microsoft OLE DB Provider for SQL Server”
- Product Name – type: SQLSERVER (with no spaces)
- Datasource – type the actual server name, and instance name using this convention: SERVERNAMEINSTANCENAME
- ProviderString – Blank
- Catalog – Optional (If entered use the default database you will be using)
- Prior to exiting, continue to the next section (defining security)
Define
the Linked Server Security
Linked server security can be
defined a few different ways. The different security methods are outlined
below. The first three options are the most common:
Option Name
|
Description
|
Be made using the login’s current
security context
|
Most Secure. Uses integrated
authentication, specifically Kerberos delegation to pass the credentials of
the current login executing the request to the linked server. The remote
server must also have the login defined. This requires establishing Kerberos
Constrained Delegation in Active Directory, unless the linked server is
another instance on the same Server. If instance is on the same server
and the logins have the appropriate permissions, I recommend this one.
|
Be made using this security
context
|
Less Secure. Uses SQL Server
Authentication to log in to the linked server. The credentials are used every
time a call is made.
|
Local server login to remote
server login mappings
|
You can specify multiple SQL
Server logins to use based upon the context of the user that is making the
call. So if you have George executing a select statement, you can have
him execute as a different user’s login when linking to the linked server.
This will allow you to not need to define “George” on the linked
server.
|
Not be made
|
If a mapping is not defined,
and/or the local login does not have a mapping, do not connect to the linked
server.
|
Be made without using a security
context
|
Connect to the server without any
credentials. I do not see a use for this unless you have security
defined as public.
|
- Within the same Dialog on the left menu under “Select a Page”, select Security
- Enter the security option of your choice.
Linked
Server Security Settings
- Click OK, and the new linked server is created
4.
The system stored procedure
sp_addlinkedserver is used in order to link a server from the server in which
you are executing the command. In order to connect to a remote SQL Server, you
basically only need 3 parameters.
Using sp_addlinkedserver
EXEC
sp_addlinkedserver
@server=N'HOGEN-PC', -- Remote Computer Name
@srvproduct=N'', -- Not Needed
@provider=N'SQLNCLI', -- SQL Server Driver
@datasrc=N'HOGEN-PCSQLEXPRESS'; -- Server Name And Instance
@server=N'HOGEN-PC', -- Remote Computer Name
@srvproduct=N'', -- Not Needed
@provider=N'SQLNCLI', -- SQL Server Driver
@datasrc=N'HOGEN-PCSQLEXPRESS'; -- Server Name And Instance
If
the remote SQL Server does not have an instance name, then the @datasrc
parameter nee only contain the remote server name and not the instance.
How to Config Linked Servers in a Minute
sp_column_privileges_ex (Transact-SQL)
SQL Server 2012
This topic has not yet been rated - Rate this topic
Returns column privileges for the
specified table on the specified linked server.
sp_column_privileges_ex [ @table_server = ] 'table_server'
[ , [ @table_name = ] 'table_name' ]
[ , [ @table_schema = ]
'table_schema' ]
[ , [ @table_catalog = ]
'table_catalog' ]
[ , [ @column_name = ] 'column_name'
]
[ @table_server = ] 'table_server'
Is the
name of the linked server for which to return information. table_server is
sysname, with no default.
[ @table_name = ] 'table_name'
Is the
name of the table that contains the specified column. table_name is sysname,
with a default of NULL.
[ @table_schema = ] 'table_schema'
Is the
table schema. table_schema is sysname, with a default of NULL.
[ @table_catalog = ] 'table_catalog'
Is the
name of the database in which the specified table_name resides. table_catalog
is sysname, with a default of NULL.
[ @column_name = ] 'column_name'
Is the
name of the column for which to provide privilege information. column_name is
sysname, with a default of NULL (all common).
The following table shows the result
set columns. The results returned are ordered by TABLE_QUALIFIER, TABLE_OWNER,
TABLE_NAME, COLUMN_NAME, and PRIVILEGE.
Column
name
|
Data
type
|
Description
|
TABLE_CAT
|
sysname
|
Table qualifier name. Various DBMS
products support three-part naming for tables (qualifier.owner.name).
In SQL Server, this column represents the database name. In some products, it
represents the server name of the table's database environment. This field
can be NULL.
|
TABLE_SCHEM
|
sysname
|
Table owner name. In SQL Server,
this column represents the name of the database user who created the table.
This field always returns a value.
|
TABLE_NAME
|
sysname
|
Table name. This field always
returns a value.
|
COLUMN_NAME
|
sysname
|
Column name, for each column of
the TABLE_NAME returned. This field always returns a value.
|
GRANTOR
|
sysname
|
Database user name that has
granted permissions on this COLUMN_NAME to the listed GRANTEE.
In SQL Server, this column is always the same as the TABLE_OWNER. This
field always returns a value.
The GRANTOR column can be
either the database owner (TABLE_OWNER) or someone to whom the
database owner granted permissions by using the WITH GRANT OPTION clause in
the GRANT statement.
|
GRANTEE
|
sysname
|
Database user name that has been
granted permissions on this COLUMN_NAME by the listed GRANTOR.
This field always returns a value.
|
PRIVILEGE
|
varchar( 32)
|
One of the available column
permissions. Column permissions can be one of the following values (or other
values supported by the data source when implementation is defined):
SELECT = GRANTEE can
retrieve data for the columns.
INSERT = GRANTEE can
provide data for this column when new rows are inserted (by the GRANTEE)
into the table.
UPDATE = GRANTEE can modify
existing data in the column.
REFERENCES = GRANTEE can
reference a column in a foreign table in a primary key/foreign key
relationship. Primary key/foreign key relationships are defined with table
constraints.
|
IS_GRANTABLE
|
varchar( 3)
|
Indicates whether the GRANTEE
is permitted to grant permissions to other users (often referred to as
"grant with grant" permission). Can be YES, NO, or NULL. An
unknown, or NULL, value refers to a data source where "grant with
grant" is not applicable.
|
Requires SELECT permission on the
schema.
The following example returns column
privilege information for the HumanResources.Department table in the
AdventureWorks2012 database on the Seattle1 linked server.
EXEC sp_column_privileges_ex @table_server = 'Seattle1',
@table_name =
'Department',
@table_schema =
'HumanResources',
@table_catalog
='AdventureWorks2012';
sp_columns_ex (Transact-SQL)
SQL Server 2012
This topic has not yet been rated - Rate this topic
Returns the column information, one
row per column, for the specified linked server tables. sp_columns_ex
returns column information for only the specific column if column is
specified.
sp_columns_ex [ @table_server = ] 'table_server'
[ , [ @table_name = ] 'table_name' ]
[ , [ @table_schema = ]
'table_schema' ]
[ , [ @table_catalog = ]
'table_catalog' ]
[ , [ @column_name = ] 'column' ]
[ , [ @ODBCVer = ] 'ODBCVer' ]
[ @table_server = ] 'table_server'
Is the
name of the linked server for which to return column information. table_server
is sysname, with no default.
[ @table_name = ] 'table_name'
Is the
name of the table for which to return column information. table_name is
sysname, with a default of NULL.
[ @table_schema = ] 'table_schema'
Is the
schema name of the table for which to return column information. table_schema
is sysname, with a default of NULL.
[ @table_catalog = ] 'table_catalog'
Is the
catalog name of the table for which to return column information. table_catalog
is sysname, with a default of NULL.
[ @column_name = ] 'column'
Is the
name of the database column for which to provide information. column is
sysname, with a default of NULL.
[ @ODBCVer = ] 'ODBCVer'
Is the
version of ODBC that is being used. ODBCVer is int, with a default of 2. This
indicates ODBC Version 2. Valid values are 2 or 3. For information about the
behavior differences between versions 2 and 3, see the ODBC SQLColumns
specification.
None
Column
name
|
Data
type
|
Description
|
TABLE_CAT
|
sysname
|
Table or view qualifier name.
Various DBMS products support three-part naming for tables (qualifier.owner.name).
In SQL Server this column represents the database name. In some products, it
represents the server name of the table's database environment. This field
can be NULL.
|
TABLE_SCHEM
|
sysname
|
Table or view owner name. In SQL
Server, this column represents the name of the database user that created the
table. This field always returns a value.
|
TABLE_NAME
|
sysname
|
Table or view name. This field
always returns a value.
|
COLUMN_NAME
|
sysname
|
Column name, for each column of
the TABLE_NAME returned. This field always returns a value.
|
DATA_TYPE
|
smallint
|
Integer value that correspond to
ODBC type indicators. If this is a data type that cannot be mapped to an ODBC
type, this value is NULL. The native data type name is returned in the TYPE_NAME
column.
|
TYPE_NAME
|
varchar( 13)
|
String representing a data type.
The underlying DBMS presents this data type name.
|
COLUMN_SIZE
|
int
|
Number of significant digits. The
return value for the PRECISION column is in base 10.
|
BUFFER_LENGTH
|
int
|
Transfer size of the data.1
|
DECIMAL_DIGITS
|
smallint
|
Number of digits to the right of
the decimal point.
|
NUM_PREC_RADIX
|
smallint
|
Is the base for numeric data
types.
|
NULLABLE
|
smallint
|
Specifies nullability.
1 = NULL is possible.
0 = NOT NULL.
|
REMARKS
|
varchar( 254)
|
This field always returns NULL.
|
COLUMN_DEF
|
varchar( 254)
|
Default value of the column.
|
SQL_DATA_TYPE
|
smallint
|
Value of the SQL data type as it
appears in the TYPE field of the descriptor. This column is the same as the DATA_TYPE
column, except for the datetime and SQL-92 interval data types. This
column always returns a value.
|
SQL_DATETIME_SUB
|
smallint
|
Subtype code for datetime and
SQL-92 interval data types. For other data types, this column returns
NULL.
|
CHAR_OCTET_LENGTH
|
int
|
Maximum length in bytes of a
character or integer data type column. For all other data types, this column
returns NULL.
|
ORDINAL_POSITION
|
int
|
Ordinal position of the column in
the table. The first column in the table is 1. This column always returns a
value.
|
IS_NULLABLE
|
varchar( 254)
|
Nullability of the column in the
table. ISO rules are followed to determine nullability. An ISO SQL-compliant
DBMS cannot return an empty string.
YES = Column can include NULLS.
NO = Column cannot include NULLS.
This column returns a zero-length
string if nullability is unknown.
The value returned for this column
is different from the value returned for the NULLABLE column.
|
SS_DATA_TYPE
|
tinyint
|
SQL Server data type, used by
extended stored procedures.
|
For more information, see the
Microsoft ODBC documentation.
sp_columns_ex is executed by querying the COLUMNS rowset of the IDBSchemaRowset
interface of the OLE DB provider corresponding to table_server. The table_name,
table_schema, table_catalog, and column parameters are passed to this interface
to restrict the rows returned.
sp_columns_ex returns an empty result set if the OLE DB provider of the
specified linked server does not support the COLUMNS rowset of the IDBSchemaRowset
interface.
Requires SELECT permission on the
schema.
sp_columns_ex follows the requirements for delimited identifiers. For
more information, see Database
Identifiers.
The following example returns the
data type of the JobTitle column of the HumanResources.Employee table in the
AdventureWorks2012 database on the linked server Seattle1.
EXEC sp_columns_ex 'Seattle1',
'Employee',
'HumanResources',
'AdventureWorks2012',
'JobTitle';
sp_droplinkedsrvlogin (Transact-SQL)
SQL
Server 2012
Removes an existing mapping between a login on the local server running SQL
Server and a login on the linked server.Transact-SQL Syntax Conventions
sp_droplinkedsrvlogin [ @rmtsrvname= ] 'rmtsrvname' ,
[ @locallogin= ] 'locallogin'
[ @rmtsrvname
= ] 'rmtsrvname'
Is the name of a linked server that the SQL Server
login mapping applies to. rmtsrvname is sysname, with no default. rmtsrvname
must already exist.
[ @locallogin
= ] 'locallogin'
Is the SQL Server login on the local server that
has a mapping to the linked server rmtsrvname. locallogin is sysname, with no
default. A mapping for locallogin to rmtsrvname must already exist. If NULL, the default
mapping created by sp_addlinkedserver, which maps all logins
on the local server to logins on the linked server, is deleted.
If the default mapping is also deleted, only logins that have been explicitly given a login mapping to the linked server, by using sp_addlinkedsrvlogin, can access the linked server.
sp_droplinkedsrvlogin cannot be executed from within a user-defined transaction.
A. Removing the login mapping for an existing user
The following example removes the mapping for the login Mary from the local server to the linked server Accounts. Therefore, login Mary uses the default login mapping.EXEC sp_droplinkedsrvlogin 'Accounts', 'Mary'
B. Removing the default login mapping
The following example removes the default login mapping originally created by executing sp_addlinkedserver on the linked server Accounts.EXEC sp_droplinkedsrvlogin 'Accounts', NULL
sp_tables_ex (Transact-SQL)
SQL Server 2012
Returns table information about the
tables from the specified linked server.
sp_tables_ex [ @table_server = ] 'table_server'
[ , [ @table_name = ]
'table_name' ]
[ , [ @table_schema = ]
'table_schema' ]
[ , [ @table_catalog = ]
'table_catalog' ]
[ , [ @table_type = ] 'table_type' ]
[ , [@fUsePattern = ]
'fUsePattern' ]
[ @table_server= ] 'table_server'
Is the
name of the linked server for which to return table information. table_server
is sysname, with no default.
[ , [ @table_name= ] 'table_name']
Is the
name of the table for which to return data type information. table_nameis
sysname, with a default of NULL.
[ @table_schema= ] 'table_schema']
Is the
table schema. table_schemais sysname, with a default of NULL.
[ @table_catalog= ] 'table_catalog'
Is the
name of the database in which the specified table_name resides. table_catalog
is sysname, with a default of NULL.
[ @table_type= ] 'table_type'
Is the
type of the table to return. table_type is sysname, with a default of NULL, and
can have one of the following values.
Value
|
Description
|
ALIAS
|
Name of an alias.
|
GLOBAL TEMPORARY
|
Name of a temporary table
available system wide.
|
LOCAL TEMPORARY
|
Name of a temporary table
available only to the current job.
|
SYNONYM
|
Name of a synonym.
|
SYSTEM TABLE
|
Name of a system table.
|
SYSTEM VIEW
|
Name of a system view.
|
TABLE
|
Name of a user table.
|
VIEW
|
Name of a view.
|
[ @fUsePattern= ] 'fUsePattern'
Determines
whether the characters _, %, [, and ] are
interpreted as wildcard characters. Valid values are 0 (pattern matching is
off) and 1 (pattern matching is on). fUsePattern is bit, with a default of 1.
None
Column
name
|
Data
type
|
Description
|
TABLE_CAT
|
sysname
|
Table qualifier name. Various DBMS
products support three-part naming for tables (qualifier.owner.name).
In SQL Server, this column represents the database name. In some other
products, it represents the server name of the database environment of the
table. This field can be NULL.
|
TABLE_SCHEM
|
sysname
|
Table owner name. In SQL Server,
this column represents the name of the database user who created the table.
This field always returns a value.
|
TABLE_NAME
|
sysname
|
Table name. This field always
returns a value.
|
TABLE_TYPE
|
varchar(32)
|
Table, system table, or view.
|
REMARKS
|
varchar(254)
|
SQL Server does not return a value
for this column.
|
sp_tables_ex is executed by querying the TABLES rowset of the IDBSchemaRowset
interface of the OLE DB provider corresponding to table_server. The table_name,
table_schema, table_catalog, and column parameters are passed to this interface
to restrict the rows returned.
sp_tables_ex returns an empty result set if the OLE DB provider of the
specified linked server does not support the TABLES rowset of the IDBSchemaRowset
interface.
Requires SELECT permission on the
schema.
The following example returns
information about the tables that are contained in the HumanResources schema in
the AdventureWorks2012 database on the LONDON2 linked server.
EXEC sp_tables_ex @table_server = 'LONDON2',
@table_catalog = 'AdventureWorks2012',
@table_schema = 'HumanResources',
@table_type = 'TABLE';
sp_linkedservers (Transact-SQL)
SQL Server 2012
Returns the list of linked servers
defined in the local server.
sp_linkedservers
0 (success) or a nonzero number
(failure)
Column
name
|
Data
type
|
Description
|
SRV_NAME
|
sysname
|
Name of the linked server.
|
SRV_PROVIDERNAME
|
nvarchar( 128)
|
Friendly name of the OLE DB
provider managing access to the specified linked server.
|
SRV_PRODUCT
|
nvarchar( 128)
|
Product name of the linked server.
|
SRV_DATASOURCE
|
nvarchar( 4000)
|
OLE DB data source property
corresponding to the specified linked server.
|
SRV_PROVIDERSTRING
|
nvarchar( 4000)
|
OLE DB provider string property
corresponding to the linked server.
|
SRV_LOCATION
|
nvarchar( 4000)
|
OLE DB location property
corresponding to the specified linked server.
|
SRV_CAT
|
sysname
|
OLE DB catalog property
corresponding to the specified linked server.
|
Requires SELECT permission on the
schema.
Ashok Kumar Sql Development And Dba Adminstrations Techi Blog : How To Add A Linked Server >>>>> Download Now
ReplyDelete>>>>> Download Full
Ashok Kumar Sql Development And Dba Adminstrations Techi Blog : How To Add A Linked Server >>>>> Download LINK
>>>>> Download Now
Ashok Kumar Sql Development And Dba Adminstrations Techi Blog : How To Add A Linked Server >>>>> Download Full
>>>>> Download LINK