Advanced Queries and Linked Servers

Size: px
Start display at page:

Download "Advanced Queries and Linked Servers"

Transcription

1 Advanced Queries and Linked Servers Advanced Queries and Linked Servers Objectives Create dynamic SQL in stored procedures. Use SQL Server cursors. Learn how to partition data horizontally. Create partitioned views to access partitioned data. Create distributed partitioned views to access data on multiple servers. Learn about SQL Server s distributed query architecture. Use linked servers to access heterogeneous data. Use OPENROWSET to create ad hoc queries against remote data. Use OPENQUERY to create pass-through queries. Microsoft SQL Server 2000 Professional Skills Development 13-1

2 Advanced Queries and Linked Servers Dynamic SQL With the introduction of user-defined functions in SQL Server 2000, the need to build a dynamic SQL statement inside of a stored procedure has diminished. A user can simply select columns from an inline or table function to create their own dynamic SQL statements, or a scalar function can return a string consisting of a dynamic SQL statement. However, you can still write a stored procedure that can take any number of parameters and select the data based only on the criteria supplied. The technique involves creating a stored procedure with input parameters for every possible search criteria. Each input parameter is then tested to see if a value was supplied, and a dynamic SQL statement is built using only those parameter values. Stored Procedure with Dynamic WHERE Clause See AdvancedQueries.SQL The following example, procemployeesearchdynamic, has optional input parameters for every possible field used in the WHERE clause. If a parameter is supplied, then it will be used in the WHERE clause. If no parameters are supplied, then the WHERE clause will be omitted, and all of the columns and rows will be returned. This makes the stored procedure very flexible no matter what is tossed to it in the way of parameters, a result set will be returned. Here s the declaration of the stored procedure with the input parameters along with some variables to build up the dynamic SQL string and WHERE clause: CREATE PROCEDURE varchar(50) = varchar(20) = varchar(50) = varchar(25) = varchar(2) = NULL AS nvarchar(2000) nvarchar(1000) nvarchar(1000) 13-2 Microsoft SQL Server 2000 Professional Skills Development

3 Dynamic SQL If no parameters are supplied, then the SELECT statement is executed without a WHERE clause and the stored procedure ends with the RETURN statement: IF (@LastName IS NULL IS NULL IS NULL IS NULL IS NULL) BEGIN PRINT 'Selecting All Employees ' SELECT EmployeeID, LastName, FirstName, url_ address, City, State, ZipCode, HomePhone FROM tblemployee RETURN END If at least one input parameter was supplied, then build up the dynamic SQL statement and the WHERE clause: EmployeeID, LastName, FirstName, url_ address, City, State, ZipCode, HomePhone FROM Shark.dbo.tblEmployee WHERE' -- Initialize variable to empty string -- Single quotes are required to delimit -- string data. IF IS NULL + ' AND LastName=''' + '''' Microsoft SQL Server 2000 Professional Skills Development 13-3

4 Advanced Queries and Linked Servers IF IS NULL SELECT + ' AND FirstName=''' + '''' IF IS NULL + ' AND url_ address=''' + '''' IF IS NULL + ' AND City=''' + '''' IF IS NULL + ' AND State=''' + '''' Once the string for the WHERE clause is constructed, there will be an extra AND on the front of it that needs to be stripped off: The SELECT statement then gets concatenated with the WHERE clause: -- This is for debugging purposes Then the sp_executesql stored procedure is called, which caches a query plan for the execution of the stored procedure. EXEC 13-4 Microsoft SQL Server 2000 Professional Skills Development

5 Dynamic SQL When you execute the stored procedure, you ll get different result sets, depending on how many input parameters you supply. Figure 1 shows the result sets. EXEC procemployeesearchdynamic EXEC EXEC Figure 1. The result sets from executing the stored procedure with three different sets of parameters supplied. EXECUTE, EXECUTE(), and sp_executesql The EXECUTE statement, EXECUTE() function, and sp_executesql stored procedure all execute things, but there are differences in the way each one is used. EXECUTE The EXECUTE, or EXEC statement is used to execute a stored procedure by following the command with the name of the stored procedure and any appropriate parameter arguments: EXEC EXECUTE() The EXECUTE(character_string) function is different it executes a character string that contains a Transact-SQL command. You can shorten the Microsoft SQL Server 2000 Professional Skills Development 13-5

6 Advanced Queries and Linked Servers name of the function to EXEC(character_string), and the character string argument can be as long as 8 KB. The EXEC() function is not compiled until run time and the plan generated is not cached and reused. The following example executes a dynamic string that concatenates literal strings with variable values: varchar(20) varchar(20) = 'LastName' = 'tblemployee' EXEC('SELECT ' + ' FROM ' sp_executesql The sp_executesql stored procedure also executes a character string, passed in as an input parameter, but unlike EXEC(), sp_executesql generates an execution plan that gets cached and reused if the same string is executed again. Also, sp_executesql must be passed a Unicode string. If you use a variable to build the string to be executed, use the nvarchar data type in the declaration and preface any literal strings with N. The following example will cache an execution plan for the SELECT statement as long as you use the three-part naming convention for the table: nvarchar(100) = N'SELECT * FROM Shark.dbo.tblCategory' EXEC The main difference in the syntax required between the EXEC() and sp_executesql is that EXEC() will allow you to concatenate literals and variables to build up a string expression, while sp_executesql requires a string constant or a single string variable. Dynamic SQL and Permissions One issue that limits the use of dynamic stored procedures is the issue of permissions required to execute the SQL statement that has been constructed. Normally, a user is not required to have any permissions on the underlying tables the EXECUTE permission granted to them on the stored procedure is sufficient as long as the stored procedure and underlying tables have the same owner. When the tables referenced by the stored procedure and the stored procedure have the same owner, then SQL Server doesn t check the user s 13-6 Microsoft SQL Server 2000 Professional Skills Development

7 Dynamic SQL permissions on the tables. This allows users to work with data only through stored procedures. However, if the stored procedure builds up a dynamic string which is then executed using EXEC() or sp_executesql, then the user must be granted the necessary permissions on the underlying tables, or the query will fail. When SQL statements are executed dynamically inside of a stored procedure, the permissions required on the underlying tables are the same as if the SQL statement was being executed outside of the stored procedure. Unless you re willing to grant users SELECT permissions on the underlying tables, then user-defined functions are probably a better choice for creating dynamic queries. Microsoft SQL Server 2000 Professional Skills Development 13-7

8 Advanced Queries and Linked Servers Transact-SQL Cursors If you have worked with Visual Basic or Active Server Pages, you ve probably used DAO or ADO recordsets. A Transact-SQL cursor works just like a recordset by allowing you to navigate through and manipulate individual rows in a result set. Cursors use a different syntax from recordsets, so they can be confusing at first. But the underlying concepts are the same, and you use cursors for many of the same reasons you use recordsets. Cursors are expensive they should be used only when there is no alternative. SQL Server is a relational database, and working with relational sets rather than with individual rows is always going to give you better performance. A cursor allows you to iterate through the results of a select statement and to take different actions for each row, based on the values of the data. Although cursors are expensive to work with, you can reduce the cost by using the least amount of scrolling and locking forward-only, read-only cursors perform the best. When to Use Cursors The easiest answer for when to use cursors is never, and this isn t just a silly answer. In most cases you could use temp tables or some other technique for accomplishing the same result. But you may well need to work on a project where someone else has used cursors, and occasionally you ll come upon a problem for which a cursor may be the best solution. You should consider using a cursor anytime you need to perform some sort of processing on each row of a result set individually. For example, you may need to perform a complex financial computation using the data in each row. If your calculation can be expressed in a single Transact-SQL expression, then no cursor is required you can simply create a column based on that expression. However, if your calculation requires several lines of Transact-SQL, perhaps using loops and conditional logic, then you really need to process the data one row at a time. You could do this in a client application, using a recordset, or you could do it in a stored procedure on the server using a cursor. How to Use Cursors Here are the steps you need to follow in your Transact-SQL code to use a cursor for working with individual rows in a result set: Step 1: Declare the cursor. When a cursor is declared, it must not only be given a name, but also a type and scrolling method. In addition, you specify whether the cursor will be local used only in that stored procedure, or global able to be shared by several procedures. Since the data in the 13-8 Microsoft SQL Server 2000 Professional Skills Development

9 Transact-SQL Cursors following example is not going to be modified, the best choice is a fast_forward cursor type, which gives you a forward-scrolling, read-only cursor. Step 2: Open the cursor. Step 3: Fetch the first row and return its data into a set of variables separated by commas. The variables must be listed in the same order as the fields in the result set. In the procbuildselect example listed below, only one column is returned, so only one variable is Step 4: Setup a loop using the WHILE command, and check the results of each FETCH operation The Fetch status codes are detailed in Table 1. Code Definition 0 Success -1 Fetch has moved beyond the end of results (EOF) -2 Row is missing (it has been altered or deleted) Table 1. Fetch status codes. Step 5: Fetch the remaining rows, one by one, until reaching the end of the cursor. Step 6: Close and deallocate the cursor. This will release any locks and any memory that the cursor may have used. A Cursor Example This example illustrates another circumstance where a cursor may be appropriate. The example builds a stored procedure that allows you to feed it the name of a table and get back a string containing a SELECT statement that explicitly names each of the columns in the table. The names of the columns for every table are stored in a system table, syscolumns. The syscolumns table has one row for each column in the database, with an id field that identifies the table and a name field with the name of the column (plus fields for many other attributes of each column). So, to gather up the names of every column in a table, you need to visit multiple rows from syscolumns, building a SELECT statement with columns that match a particular table ID. Microsoft SQL Server 2000 Professional Skills Development 13-9

10 Advanced Queries and Linked Servers The following procedure takes the name of a table as an input parameter and opens a cursor that includes one row from syscolumns for every column in the specified table. As the code moves through the rows of the cursor, the column names are concatenated into a SELECT statement that is returned as an output parameter: CREATE PROCEDURE varchar(8000) OUTPUT AS BEGIN int varchar(130) -- Get the Object_id for the table = object_id(@tablename) IS NULL BEGIN -- Return the results in a column called SQL Not Found' RETURN -- Bail out here END -- Start building string ' -- Declare cursor DECLARE table_cursor CURSOR Local Fast_Forward FOR SELECT Name FROM syscolumns WHERE ID=@OID ORDER BY colid -- Open cursor OPEN table_cursor -- Fetch first row FETCH NEXT FROM table_cursor Microsoft SQL Server 2000 Professional Skills Development

11 Transact-SQL Cursors -- Loop through remaining rows WHILE -- Loop until no more data can be found BEGIN IF not = -2 BEGIN Select + ', ' END FETCH NEXT FROM table_cursor END -- Close and deallocate cursor CLOSE table_cursor DEALLOCATE table_cursor -- Now remove the extra comma and space off the end 1, Datalength(@SQL)-2) -- And add the FROM clause + ' FROM ' END Executing the stored procedure against the tblcategory table will return a string containing a fully-qualified (all columns named) SELECT statement. You can test the stored procedure and then execute the returned SELECT statement like this: varchar(4000) EXEC procbuildselect OUTPUT -- Show the resulting SELECT statement -- Execute the returned SELECT statement EXECUTE(@SQL) Microsoft SQL Server 2000 Professional Skills Development 13-11

12 Advanced Queries and Linked Servers Handling Large Data Sets Working with large tables can be challenging, particularly if you have a database that is being used for data entry as well as decision support. In this section you ll learn how to partition data, breaking it up into separate tables, and creating partitioned views to join it back together again. Horizontally Partitioning Tables When a single table becomes too large to work with efficiently, it can be horizontally partitioned by being broken into separate tables. Each table has an identical schema, but each contains a separate and distinct range of data. For example, you could split a table on an ID column value, where values 10,000 to 20,000 are stored in one partition, values 20,001 to 30,000 are stored in another partition, and so on. Each partition has the same number of columns, but fewer rows than the original table. You can also partition on other column values, such as date ranges, regions, or other industry-specific codes. Each table must have a CHECK constraint enforcing the range of values so that there is no overlap between tables. If you wanted to partition your enormous Sales table, here s an example of the script you d use to create a simple table named tblsales1 with an ID value range starting at 10,000: CREATE TABLE dbo.tblsales1 (ID int NOT NULL IDENTITY (10000, 1), SalesData money NOT NULL) ON [PRIMARY] GO Microsoft SQL Server 2000 Professional Skills Development

13 Handling Large Data Sets You d then create tblsales2 with an IDENTITY seed of 20,001, and tblsales3 with an IDENTITY seed of 30,001: CREATE TABLE dbo.tblsales2 (ID int NOT NULL IDENTITY (20001, 1), SalesData money NOT NULL) ON [PRIMARY] GO CREATE TABLE dbo.tblsales3 (ID int NOT NULL IDENTITY (30001, 1), SalesData money NOT NULL) ON [PRIMARY] GO After creating each of the tables, you need to create a CHECK constraint that strictly limits the values that can be inserted into the ID column. Here s the CHECK constraint for tblsales1, tblsales2, and tblsales3: ALTER TABLE dbo.tblsales1 ADD CONSTRAINT CK_tblSales1 CHECK (ID BETWEEN AND 20000) ALTER TABLE dbo.tblsales2 ADD CONSTRAINT CK_tblSales2 CHECK (ID BETWEEN AND 30000) ALTER TABLE dbo.tblsales3 ADD CONSTRAINT CK_tblSales3 CHECK (ID BETWEEN AND 40000) Once you ve partitioned the table and it s now many separate tables, you need an efficient way to query all of the separate tables. This is where a horizontally partitioned view comes in. You can query the view without having to worry about the fact that there are actually three separate tables involved. Use the UNION ALL operator to join the tables together in the view: Microsoft SQL Server 2000 Professional Skills Development 13-13

14 Advanced Queries and Linked Servers CREATE VIEW vwsalesunionall AS SELECT * FROM dbo.tblsales1 UNION ALL SELECT * FROM dbo.tblsales2 UNION ALL SELECT * FROM dbo.tblsales3 TIP: Always use UNION ALL over a plain UNION statement even when you know there are no duplicate records. If you omit the ALL keyword, SQL Server will take another pass through the query to eliminate any duplicates, slowing down performance. The beauty of using a partitioned view is that SQL Server won t waste time looking through all the tables to fulfill a query that works with a specific range of data that falls within the values limited by the CHECK constraint. The SQL Server engine will quickly examine all the tables that comprise the view and determine which tables have the required data through the check constraints. The engine will then query the appropriate table without attempting to select any records from the other tables that form part of the union. The following SELECT statement from vwsalesunionall will cause SQL Server to look only in the tblsales2 table because the WHERE clause values fall within the CHECK constraint defined for tblsales2: SELECT * FROM vwsalesunionall WHERE ID BETWEEN AND Partitioning increases performance by using less I/O to find and retrieve the requested data. Later in this chapter you ll learn about distributed partitioned views, where data can be partitioned across multiple servers. Partitioned views are updatable as long as they meet the following conditions: The view definition comprises a series of SELECT statements whose individual result sets are combined using the UNION ALL operator. Each single SELECT statement references a single SQL Server base table. The table can be either a local table, or a remote table. In addition, partitioned views can also be updated with INSTEAD OF triggers Microsoft SQL Server 2000 Professional Skills Development

15 Handling Large Data Sets Distributed Partitioned Views Distributed partitioned views allow you to access tables that have not only been partitioned, but are also located on remote servers. A distributed partitioned view allows you to retrieve data from each data source, presenting it as though it came from a single table on a single server. The implementation of distributed partitioned views in SQL Server is designed for high-end OLTP (Online Transaction Processing) and Web site databases with individual SQL statements retrieving minimal data from enormous tables. Distributed partitioned views give you an edge when you have large tables partitioned on multiple servers. Queries accessing only a fraction of the data can run faster because there s less data to scan. If the tables are located on different servers or on a computer with multiple processors, each table involved in the query can also be scanned in parallel, thereby improving query performance. Additionally, maintenance tasks, such as rebuilding indexes or backing up a table, can execute more quickly. By using a partitioned view, the data still appears as a single table and can be queried as such without having to reference the correct underlying table manually. Here are the steps for setting up distributed partitioned views: 1. Add each member server as a linked server. The view needs direct access to data located on all of the other servers. All tables must have the same format, the same number of columns, and the columns must have the same attributes. The range of values must be enforced by a CHECK constraint, and the ranges can t overlap. 2. Create multiple databases, each on a different member server running an instance of SQL Server. 3. Use the sp_serveroption system stored procedure on each server to set the lazy schema validation option. What this does is prevent the query processor from requesting meta data for the linked tables until it actually needs the data, thus boosting performance. 4. Create a partitioned view using the UNION ALL operator on each server, using the same name for each one. This allows queries referencing the distributed partitioned view name to run on any of the member servers. When designing the partitions, try to partition the data so that related data is placed together on a member server. In addition, a partition should allow all rows to be placed on the same server as all of their referenced foreign key rows. In other words, you don t want to be doing cross-server joins. The partition should be defined on a column that most evenly distributes the data among the partitioned tables. This depends on your data in some cases, the primary key may be suitable, or perhaps a region or date. Microsoft SQL Server 2000 Professional Skills Development 13-15

16 Advanced Queries and Linked Servers Here s how you d rewrite the view used in the previous example if it were a distributed partitioned view: CREATE VIEW vwsalesdistributed AS SELECT * FROM ThisDatabase.dbo.tblSales1 UNION ALL SELECT * FROM LinkedServer2.Database2.dbo.tblSales2 UNION ALL SELECT * FROM LinkedServer3.Database3.dbo.tblSales3 Each of the linked servers needs its own copy of the distributed partitioned view that references the other servers. You d create a version of vwsalesdistributed on LinkedServer2 and LinkedServer3 that are customized to those servers, so that all of the servers talk to each other. Setting up linked servers is covered later in this chapter. TIP: Distributed partitioned views are not updatable. Use an INSTEAD OF trigger when you need to perform updates to a table through a distributed partitioned view. Distributed partitioned views allow you to scale out your database in a very transparent way. To a user selecting data from the view, it appears as though the data is being fetched from a single table in a single database on a single server. Distributed partitioned views can also be used to implement a federation of database servers. Each server is administered independently, but they cooperate to share the processing load. This allows you to scale out a set of servers to support the processing requirements of extremely large and/or hightransaction-rate databases. See the Books Online topic, Designing Federated Database Servers for more information. Vertically Partitioning Tables Vertical partitioning divides a single table into multiple tables based on selected columns rather than by values. This is useful when large data fields known as BLOBs (binary large objects) are required, but not constantly used. BLOBs in SQL Server consist of data stored in text, ntext, or image data types. If you have image data stored in a database, it can be partitioned vertically by creating a separate table so that it is not retrieved except when needed Microsoft SQL Server 2000 Professional Skills Development

17 Handling Large Data Sets For example, if you have an image consisting of the bitmap rendering of an ID photo for an employee, it can be located in a separate table linked back to the Employee table in a one-to-one relationship on the EmployeeID, as shown in Figure 2. Figure 2. Image data can be vertically partitioned by locating it in a separate table. By partitioning the image into a separate table, storage space requirements are reduced in the tblemployee table. Queries that select all columns (*) from tblemployees will no longer pull down the image data. Text in Row Text in row is a new feature in SQL Server 2000 that improves the speed with which small-to-medium size text, ntext, or image column data can be retrieved. Normally, only pointers are stored in the row. These pointers point to the root node of a tree built of internal pointers that map to the data pages in which string fragments of the BLOBs are actually stored. However, if the text or image data is small enough, you can enable the text in row property of the table to allow the data to be stored in the row itself, instead of storing the pointers. This makes reading the contents of these columns as fast as reading or writing character and binary strings because SQL Server does not have to access separate pages to read or write the BLOB string. There must be sufficient room left in the row to hold the data the maximum row size in SQL Server 2000 is 8 KB, and the maximum size allowed for the text, ntext, or image data is 7,000 bytes, or 7 KB. There are two ways to enable text in row, and each uses the sp_tableoption stored procedure: sp_tableoption N'tblEmployeePhoto', 'text in row', 'ON' Microsoft SQL Server 2000 Professional Skills Development 13-17

18 Advanced Queries and Linked Servers This will turn on text in row, but the limit in size for the photo would be 256 bytes. To enable a larger image, specify the bytes instead of using ON. The following example will set the maximum size to the limit of 7,000 bytes. sp_tableoption N'tblEmployeePhoto', 'text in row', '7000' If the image being stored is larger than 7 KB, then it will not be stored in the row, pointers will be stored instead Microsoft SQL Server 2000 Professional Skills Development

19 Distributed Queries Distributed Queries Distributed queries in SQL Server allow you to access data stored on multiple computers that are running SQL Server or to access heterogeneous data sources. These heterogeneous data sources can be either relational or nonrelational for which either an OLE DB provider or ODBC driver exists. In other words, you can get at your Oracle data, your Access data, or data stored in a text file that you normally access in Notepad. This data appears as though it was just another SQL Server table. SQL Server can be used as a gateway to all other database platforms and vendors within your enterprise. The Distributed Architecture Prior to SQL Server 7.0, client applications that needed to reference data on multiple platforms (or multiple servers), were required to purchase client access licenses for each platform and to distribute all of the necessary ODBC libraries and communications component to every client application that used them. Each client application then was required to have its own connection to the data source. Figure 3 shows what that architecture looked like. Figure 3. Client requirements without using distributed queries. With the introduction of SQL Server 7.0, the distributed architecture was implemented with the concept of linked servers, which is illustrated in Figure 4. The only client requirement is that the OLE DB provider for SQL Server be installed. All other components and protocols needed can be installed on the Microsoft SQL Server 2000 Professional Skills Development 13-19

20 Advanced Queries and Linked Servers SQL Server machine, with SQL Server providing the gateway to diverse data sources. Figure 4. Using SQL Server as a gateway for distributed queries. There are two ways to take advantage of this architecture: Ad hoc queries. You can use the OPENROWSET or OPENQUERY functions (discussed later in this chapter) to query remote data. This is generally used when the query is a one-time-only occasion. Linked servers. You can set up a linked server, which registers the server so that SQL Server knows where to look for the remote data and objects. This is useful when you repeatedly query remote data because the link is already configured. The next section covers setting up linked servers. Setting Up Linked Servers You can use either the Enterprise Manager or system stored procedures to configure a linked server. Try It Out! Follow these steps to set up a linked server to the Microsoft Access Northwind.mdb data base using the Enterprise Manager: 1. From the registered server, expand the Security node Microsoft SQL Server 2000 Professional Skills Development

21 Distributed Queries 2. Right-click on Linked Servers. 3. Select New Linked Server from the menu. This loads the Linked Server Properties dialog box shown in Figure 5. Figure 5. Creating a linked server to the Northwind database. 4. Type a name that you will use when you query the linked server in the Linked server text box. Select the Microsoft Jet 4.0 OLE DB Provider, and in the Data Source, type in the path and filename where Northwind.mdb can be found. It s usually located in the \Program Files\Microsoft Office\Office\Samples directory if you ve done a full install of Office. 5. This is all of the information that s required filling in the other fields is optional for an Access database. Click OK when finished. The information you need to supply depends on the requirements of the OLE DB provider. The Access Northwind database does not have any security requirements, so you can ignore the Security tab. However, if you re linking to an Oracle database, you ll need to provide an appropriate login and password. Microsoft SQL Server 2000 Professional Skills Development 13-21

22 Advanced Queries and Linked Servers Using sp_addlinkedserver You can set up a linked server using the sp_addlinkedserver system stored procedure. Here s the syntax: sp_addlinkedserver [@server =] 'server' [, [@srvproduct =] 'product_name'] [, [@provider =] 'provider_name'] [, [@datasrc =] 'data_source'] [, [@location =] 'location'] [, [@provstr =] 'provider_string'] [, [@catalog =] 'catalog'] As you can see, the information provided in the parameters matches the information in the Linked Server dialog box displayed in the Enterprise Manager. Use this syntax to create a login to the Access Northwind database: = = = 'OLE DB Provider for = 'D:\Programs\Northwind.mdb' If you re linking an unsecured Access database, you re done. However, if you are linking to a server that requires authentication, then you must use the sp_addlinkedsrvlogin stored procedure to add a login to be used. Here s the syntax: sp_addlinkedsrvlogin [@rmtsrvname =] 'rmtsrvname' [,[@useself =] 'useself'] [,[@locallogin =] 'locallogin'] [,[@rmtuser =] 'rmtuser'] [,[@rmtpassword =] 'rmtpassword'] Microsoft SQL Server 2000 Professional Skills Development

23 Distributed Queries NOTE If you are running linked SQL Servers only, you can map login accounts and passwords between local and remote SQL Servers by using the sp_addlinkedsrvlogin system stored procedure. When you map a local account to a remote login account, you do not have to create a login account and password for each user on the remote SQL Server. If the Access database was secured, and you wanted to use the Admin user account with a password of password, then you d need to add the login: = 'password' Note that the login and password must already exist in the Access database. NOTE If you are working with a secured Access database, you must place the name and location of the workgroup file (the default is system.mdw) in the following registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\ Engines\SystemDB Unfortunately, SQL Server does not allow for the fact that you might have multiple workgroup files or work with multiple secured Access databases. So the bottom line is that you can only link to Access databases that all use the same workgroup file. Microsoft SQL Server 2000 Professional Skills Development 13-23

24 Advanced Queries and Linked Servers Querying Linked Servers You can t do much with a linked server in the Enterprise Manager except view a list of the linked tables by expanding the Tables node, as shown in Figure 6 for the tables in the Access Northwind database. Figure 6. The tables in the Access Northwind database. However, that same list is also provided by the sp_tables_ex system stored procedure. A partial result set is shown in Figure 7. Note that sp_tables_ex displays all of the Access systems tables and does not filter any of them out. EXEC sp_tables_ex 'AccessNwind' Figure 7. Getting a list of tables in the linked server Microsoft SQL Server 2000 Professional Skills Development

25 Distributed Queries TIP: Other system stored procedures that return information about linked servers include sp_linkedservers, sp_catalogs, sp_indexes, sp_primarykeys, and sp_columns_ex. Selecting Data from a Linked Server The syntax you need to query a linked server is slightly different than syntax you use with normal SQL Server tables in that it requires a special four-part naming convention: LinkedServerName.Catalog.Schema.TableName As you can see from Figure 7, there are only NULLs listed in the TABLE_CAT and TABLE_SCHEM columns for an Access database, so you can omit the catalog and schema arguments and just type the three dots between the linked server name and the name of the table you re interested in. The following query will select the CategoryName and Description from the Northwind Categories table. The results are shown in Figure 8. SELECT CategoryName, Description FROM AccessNwind...Categories Figure 8. The result set from a linked server query. Microsoft SQL Server 2000 Professional Skills Development 13-25

26 Advanced Queries and Linked Servers You can work with linked tables as though they were local tables, as long as you adhere to the four-part naming convention. The following query joins the Northwind Category table to the Shark tblcategory on Category ID and lists categories with the same ID. The result set is shown in Figure 9. SELECT Linked.CategoryName, Local.Category FROM AccessNwind...Categories AS Linked INNER JOIN Shark.dbo.tblCategory AS Local ON Linked.CategoryID = Local.CategoryID Figure 9. The result set from the heterogeneous join between the Access Northwind and the SQL Server Shark categories tables. If linked server queries seem a little slow to you, it s probably because at least part of the query is being processed on the remote server. In the case of the above example, the Jet engine has to wake up and select all of the rows from the Categories table and pass them back to SQL Server so the rows can be joined to the tblcategory table. For that reason, queries executed on a linked server are known as pass-through queries. TIP: If you are running any kind of distributed queries from your client applications, make sure to set the SET ANSI_NULLS ON and SET ANSI_WARNINGS ON options prior to issuing the queries. These options are set to ON in the Query Analyzer by default, but that may not be the case with your client application. Ad Hoc Querying Ad hoc querying is useful when you do not expect to reuse the query later, and you don t want to go to the trouble of setting up a linked server. You can use the OPENROWSET function when you need to execute a query against a remote source only once Microsoft SQL Server 2000 Professional Skills Development

27 Distributed Queries OPENROWSET The OPENROWSET function lets you create an ad hoc query without having to set up a linked server. As you d expect, all of the connection information is required as part of the syntax for the OPENROWSET function: OPENROWSET('provider_name' {'datasource'; 'user_id'; 'password' 'provider_string'}, {[catalog.][schema.]object 'query'}) The following query uses OPENROWSET, passing in the connection information needed to connect to the Access Northwind database. Note that here you must supply a user ID and password (Admin with no password is used for an unsecured Access database). The OPENROWSET function executes the following pass-through query in Access, returning the result set to SQL Server. The result set is shown in Figure 10. SELECT Nwind.CategoryName FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'D:\Programs\Northwind.mdb'; 'Admin';'', 'SELECT CategoryName FROM Categories') AS Nwind Figure 10. Using OPENROWSET against the Access Northwind Categories table. OPENQUERY OPENQUERY differs from OPENROWSET in that it requires a linked server in order to operate. It is also much slower than OPENROWSET, so you wouldn t want to use it in preference to querying the linked server directly, using the Transact-SQL four-part naming syntax. The advantage of Microsoft SQL Server 2000 Professional Skills Development 13-27

28 Advanced Queries and Linked Servers OPENQUERY is that it allows you to create pass-through queries using provider-specific syntax. In other words, your query uses whatever dialect of SQL the provider uses. Here s the syntax for OPENQUERY: OPENQUERY (LinkedServerName, query) The following example executes an Access cross-tab query, the syntax of which is completely illegal in Transact-SQL. In addition, the query also uses Access-specific functions like DatePart. The result set is shown in Figure 11. SELECT * FROM OPENQUERY( AccessNwind, 'TRANSFORM Sum(CCur([Order Details].[UnitPrice]*[Quantity]* (1-[Discount])/100)*100) AS ProductAmount SELECT Products.ProductName FROM Products INNER JOIN (Orders INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID) ON Products.ProductID = [Order Details].ProductID WHERE (((Orders.OrderDate) Between #1/1/1997# And #12/31/1997#)) GROUP BY Products.ProductName PIVOT "Qtr " & DatePart("q",[OrderDate],1,0) In ("Qtr 1","Qtr 2","Qtr 3","Qtr 4");' ) Figure 11. The result set from an Access pass-through query using OPENQUERY. OPENQUERY allows you to use provider-specific syntax that SQL Server simply couldn t process. This is useful for querying data from an OLAP cube Microsoft SQL Server 2000 Professional Skills Development

29 Distributed Queries or other data sources such as Microsoft Index Server, where the syntax used has no relationship to Transact-SQL whatsoever. OPENQUERY allows you to query the data source using its native syntax, but returns the result set in such a way that SQL Server can present it to the client as though it were native SQL Server data. Microsoft SQL Server 2000 Professional Skills Development 13-29

30 Advanced Queries and Linked Servers Summary Create dynamic SQL in stored procedures using the EXEC() or sp_executesql methods. SQL Server cursors can be used like client-side recordsets when you need to iterate through data a row at a time. Partitioning data horizontally gives a performance boost to larger tables. Partitioned views can access partitioned data as though it were in one table. Distributed partitioned views allow access to partitioned data on multiple servers. Data can be partitioned vertically to allow efficient storage of BLOB (text, ntext, and image) data. BLOBs can be stored in normal table rows by setting the text in row option in a table. SQL Server s distributed query architecture allows you to use SQL Server as a gateway to many different data sources. Linked servers set up a permanent connection to multiple data sources. The OPENROWSET function allows you to create ad hoc queries against remote data. The OPENQUERY function allows you to create pass-through queries using the provider s native syntax Microsoft SQL Server 2000 Professional Skills Development

31 Distributed Queries Questions 1. Does a user need permissions on the underlying tables when issuing a dynamic query inside of a stored procedure using EXECUTE() or sp_executesql? 2. When should you choose to use a cursor over using Transact-SQL statements? 3. How does a partitioned view know in which table a range of data is located? 4. What does the text in row setting do? 5. Name two ways to set up a linked server. 6. What is the difference between OPENROWSET and OPENQUERY? Microsoft SQL Server 2000 Professional Skills Development 13-31

32 Advanced Queries and Linked Servers Answers 1. Does a user need permissions on the underlying tables when issuing a dynamic query inside of a stored procedure using EXECUTE() or sp_executesql? Yes. Even if the user has EXECUTE permissions on the stored procedure, they still need SELECT on the underlying tables since the string is being processed separately. 2. When should you choose to use a cursor over using Transact-SQL statements? If there s another way to do something, then never. Choose to use cursors only when there s no other way to accomplish a particular programming task. 3. How does a partitioned view know in which table a range of data is located? By the CHECK constraint created in the underlying tables that used to enforce the range of data in the table. 4. What does the text in row setting do? Allows you to store small-to-medium size text, ntext, or image data in a data row. 5. Name two ways to set up a linked server. Use the Enterprise Manager by going into the Linked Servers Node, or by running the sp_addlinkedserver system stored procedure. 6. What is the difference between OPENROWSET and OPENQUERY? OPENQUERY requires a linked server and OPENROWSET does not. OPENQUERY allows you to use the syntax of the provider, whereas OPENROWSET uses Transact-SQL Microsoft SQL Server 2000 Professional Skills Development

33 Distributed Queries Lab 13: Advanced Queries and Linked Servers TIP: Because this lab includes a great deal of typed code, we ve tried to make it simpler for you. You ll find all the code in AdvancedQueriesLab.SQL, in the same directory as the sample project. To avoid typing the code, you can cut/paste it from the text file instead. Microsoft SQL Server 2000 Professional Skills Development 13-33

34 Lab 13: Advanced Queries and Linked Servers Lab 13 Overview In this lab you ll learn how to set up a linked server to the Access Northwind.mdb database. You ll learn how to find out what tables and columns are available on the linked server, and build a query against it. To complete this lab, you ll need to work through two exercises: Setting Up a Linked Server Remote Querying Each exercise includes an Objective section that describes the purpose of the exercise. You are encouraged to try to complete the exercise from the information given in the Objective section. If you require more information to complete the exercise, the Objective section is followed by detailed step-bystep instructions Microsoft SQL Server 2000 Professional Skills Development

35 Setting Up a Linked Server Setting Up a Linked Server Objective In this exercise, you ll create a linked server to the Northwind.mdb Access database using the Enterprise Manager. You ll then use the sp_tables_ex stored procedure to find out what tables are available for querying. Things to Consider Where is the Northwind.mdb Access database located on your computer? You ll need to search for it in Windows Explorer before setting up the link. How do you set up a linked server using the Enterprise Manager? Which pieces of information are required to set up a linked Access server? How do you run the sp_tables_ex stored procedure? Step-by-Step Instructions 1. Right-click the Security Linked Servers node in the Enterprise Manager and select New Linked Server from the menu. 2. This loads the Linked Server Properties dialog box. Type the name NorthwindLink for the linked server name. Select the Microsoft Jet 4.0 OLE DB Provider from the drop-down listbox. Type in the location of the Northwind.mdb database on your machine. The location and filename would be the following string if Office was installed on your C:\ drive: C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb Microsoft SQL Server 2000 Professional Skills Development 13-35

36 Lab 13: Advanced Queries and Linked Servers 3. The completed dialog box should look like that shown in Figure 12. Click OK when finished. Figure 12. Setting up the NorthwindLink linked server. 4. To find out which tables are available, open the Query Analyzer and type in the following statement: EXEC sp_tables_ex 'NorthwindLink' 5. Execute the statement by pressing the F5 key. This will give you a list of tables that you can query in the Northwind.mdb database, as shown in Figure 13. Figure 13. The list of tables in the NorthwindLink linked server Microsoft SQL Server 2000 Professional Skills Development

37 Remote Querying Remote Querying Objective In this exercise, you ll create a SELECT query based on the Product Sales for 1997 view in the NorthwindLink linked server. You ll then create aggregate queries to sum the output, grouping by category and by quarter. Things to Consider What is the syntax used when selecting data from a linked server? How do you deal with names that have spaces in them? How do you create an aggregate query on linked server data? Step-by-Step Instructions 1. Create the following query in the Query Analyzer: SELECT * FROM NorthwindLink...[Product Sales for 1997] 2. Execute the query by pressing the F5 key. The output should look like that shown in Figure 14. Figure 14. The output from the Product Sales for 1997 query. Microsoft SQL Server 2000 Professional Skills Development 13-37

38 Lab 13: Advanced Queries and Linked Servers 3. To summarize product sales by category, write the following query: SELECT CategoryName, SUM(ProductSales) AS Total FROM NorthwindLink...[Product Sales for 1997] GROUP BY CategoryName 4. Run the query by pressing the F5 key. The result set is shown in Figure 15. Figure 15. Summarizing the Product Sales for 1997 by category. 5. To summarize by quarter, type the following query: SELECT ShippedQuarter AS Quarter, SUM(ProductSales) AS Total FROM NorthwindLink...[Product Sales for 1997] GROUP BY ShippedQuarter 6. Press F5 to execute the query. The result set is shown in Figure 16. Figure 16. Summarizing the Product Sales for 1997 by quarter Microsoft SQL Server 2000 Professional Skills Development

Linked Servers. Functionality and Performance Considerations for Linked Servers

Linked Servers. Functionality and Performance Considerations for Linked Servers Linked Servers Linked servers provide SQL Server with access to data from remote data sources. Depending on the remote data source, you can issue queries, perform data modifications, and execute remote

More information

Using the Query Analyzer

Using the Query Analyzer Using the Query Analyzer Using the Query Analyzer Objectives Explore the Query Analyzer user interface. Learn how to use the menu items and toolbars to work with SQL Server data and objects. Use object

More information

Full Text Search. Objectives. Full Text Search

Full Text Search. Objectives. Full Text Search Full Text Search Full Text Search Objectives Learn about full-text search capabilities in SQL Server 2000. Configure a database for full-text search. Write queries using full-text search syntax. Use full-text

More information

SQL Server An Overview

SQL Server An Overview SQL Server An Overview SQL Server Microsoft SQL Server is designed to work effectively in a number of environments: As a two-tier or multi-tier client/server database system As a desktop database system

More information

Developing Web Applications for Microsoft SQL Server Databases - What you need to know

Developing Web Applications for Microsoft SQL Server Databases - What you need to know Developing Web Applications for Microsoft SQL Server Databases - What you need to know ATEC2008 Conference Session Description Alpha Five s web components simplify working with SQL databases, but what

More information

Chapter 4 Accessing Data

Chapter 4 Accessing Data Chapter 4: Accessing Data 73 Chapter 4 Accessing Data The entire purpose of reporting is to make sense of data. Therefore, it is important to know how to access data locked away in the database. In this

More information

SQL Server. 2012 for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

SQL Server. 2012 for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach TRAINING & REFERENCE murach's SQL Server 2012 for developers Bryan Syverson Joel Murach Mike Murach & Associates, Inc. 4340 N. Knoll Ave. Fresno, CA 93722 www.murach.com [email protected] Expanded

More information

Title. Syntax. stata.com. odbc Load, write, or view data from ODBC sources. List ODBC sources to which Stata can connect odbc list

Title. Syntax. stata.com. odbc Load, write, or view data from ODBC sources. List ODBC sources to which Stata can connect odbc list Title stata.com odbc Load, write, or view data from ODBC sources Syntax Menu Description Options Remarks and examples Also see Syntax List ODBC sources to which Stata can connect odbc list Retrieve available

More information

ODBC Client Driver Help. 2015 Kepware, Inc.

ODBC Client Driver Help. 2015 Kepware, Inc. 2015 Kepware, Inc. 2 Table of Contents Table of Contents 2 4 Overview 4 External Dependencies 4 Driver Setup 5 Data Source Settings 5 Data Source Setup 6 Data Source Access Methods 13 Fixed Table 14 Table

More information

Data Tool Platform SQL Development Tools

Data Tool Platform SQL Development Tools Data Tool Platform SQL Development Tools ekapner Contents Setting SQL Development Preferences...5 Execution Plan View Options Preferences...5 General Preferences...5 Label Decorations Preferences...6

More information

Introducing Microsoft SQL Server 2012 Getting Started with SQL Server Management Studio

Introducing Microsoft SQL Server 2012 Getting Started with SQL Server Management Studio Querying Microsoft SQL Server 2012 Microsoft Course 10774 This 5-day instructor led course provides students with the technical skills required to write basic Transact-SQL queries for Microsoft SQL Server

More information

MS SQL Performance (Tuning) Best Practices:

MS SQL Performance (Tuning) Best Practices: MS SQL Performance (Tuning) Best Practices: 1. Don t share the SQL server hardware with other services If other workloads are running on the same server where SQL Server is running, memory and other hardware

More information

Querying Microsoft SQL Server

Querying Microsoft SQL Server Course 20461C: Querying Microsoft SQL Server Module 1: Introduction to Microsoft SQL Server 2014 This module introduces the SQL Server platform and major tools. It discusses editions, versions, tools used

More information

FileMaker 12. ODBC and JDBC Guide

FileMaker 12. ODBC and JDBC Guide FileMaker 12 ODBC and JDBC Guide 2004 2012 FileMaker, Inc. All Rights Reserved. FileMaker, Inc. 5201 Patrick Henry Drive Santa Clara, California 95054 FileMaker and Bento are trademarks of FileMaker, Inc.

More information

INTRODUCTION: SQL SERVER ACCESS / LOGIN ACCOUNT INFO:

INTRODUCTION: SQL SERVER ACCESS / LOGIN ACCOUNT INFO: INTRODUCTION: You can extract data (i.e. the total cost report) directly from the Truck Tracker SQL Server database by using a 3 rd party data tools such as Excel or Crystal Reports. Basically any software

More information

Performance Implications of Various Cursor Types in Microsoft SQL Server. By: Edward Whalen Performance Tuning Corporation

Performance Implications of Various Cursor Types in Microsoft SQL Server. By: Edward Whalen Performance Tuning Corporation Performance Implications of Various Cursor Types in Microsoft SQL Server By: Edward Whalen Performance Tuning Corporation INTRODUCTION There are a number of different types of cursors that can be created

More information

Advantage Database Server

Advantage Database Server white paper Advantage Database Server Migrating From Microsoft Access Jet Database Engine Bill Todd, The Database Group, Inc. TABLE OF CONTENTS 1 Introduction 2 Microsoft s Solution 2 Is Advantage Database

More information

Access Queries (Office 2003)

Access Queries (Office 2003) Access Queries (Office 2003) Technical Support Services Office of Information Technology, West Virginia University OIT Help Desk 293-4444 x 1 oit.wvu.edu/support/training/classmat/db/ Instructor: Kathy

More information

Using SQL Server Management Studio

Using SQL Server Management Studio Using SQL Server Management Studio Microsoft SQL Server Management Studio 2005 is a graphical tool for database designer or programmer. With SQL Server Management Studio 2005 you can: Create databases

More information

How to Use PIPS Access to/from SQL Database Utility Program. By PIPSUS Support Team Dr. Chouikha ([email protected])

How to Use PIPS Access to/from SQL Database Utility Program. By PIPSUS Support Team Dr. Chouikha (achouikha@gmail.com) How to Use PIPS Access to/from SQL Database Utility Program By PIPSUS Support Team Dr. Chouikha ([email protected]) 1. Introduction PIPS (Price Index Processor Software) data transfer utility program

More information

Database Query 1: SQL Basics

Database Query 1: SQL Basics Database Query 1: SQL Basics CIS 3730 Designing and Managing Data J.G. Zheng Fall 2010 1 Overview Using Structured Query Language (SQL) to get the data you want from relational databases Learning basic

More information

SAP Business Objects Business Intelligence platform Document Version: 4.1 Support Package 7 2015-11-24. Data Federation Administration Tool Guide

SAP Business Objects Business Intelligence platform Document Version: 4.1 Support Package 7 2015-11-24. Data Federation Administration Tool Guide SAP Business Objects Business Intelligence platform Document Version: 4.1 Support Package 7 2015-11-24 Data Federation Administration Tool Guide Content 1 What's new in the.... 5 2 Introduction to administration

More information

Microsoft Access 3: Understanding and Creating Queries

Microsoft Access 3: Understanding and Creating Queries Microsoft Access 3: Understanding and Creating Queries In Access Level 2, we learned how to perform basic data retrievals by using Search & Replace functions and Sort & Filter functions. For more complex

More information

Backups and Maintenance

Backups and Maintenance Backups and Maintenance Backups and Maintenance Objectives Learn how to create a backup strategy to suit your needs. Learn how to back up a database. Learn how to restore from a backup. Use the Database

More information

MAS 500 Intelligence Tips and Tricks Booklet Vol. 1

MAS 500 Intelligence Tips and Tricks Booklet Vol. 1 MAS 500 Intelligence Tips and Tricks Booklet Vol. 1 1 Contents Accessing the Sage MAS Intelligence Reports... 3 Copying, Pasting and Renaming Reports... 4 To create a new report from an existing report...

More information

Using the SQL Server Linked Server Capability

Using the SQL Server Linked Server Capability Using the SQL Server Linked Server Capability SQL Server s Linked Server feature enables fast and easy integration of SQL Server data and non SQL Server data, directly in the SQL Server engine itself.

More information

Technical Bulletin 005 Revised 2010/12/10

Technical Bulletin 005 Revised 2010/12/10 sitesecuresoftware.com Site-Secure Facility & Security Management Software Technical Bulletin 005 Revised 2010/12/10 Search Active Directory from SQL Server 2000-2005 Table of Contents Introduction...

More information

Course ID#: 1401-801-14-W 35 Hrs. Course Content

Course ID#: 1401-801-14-W 35 Hrs. Course Content Course Content Course Description: This 5-day instructor led course provides students with the technical skills required to write basic Transact- SQL queries for Microsoft SQL Server 2014. This course

More information

FileMaker 11. ODBC and JDBC Guide

FileMaker 11. ODBC and JDBC Guide FileMaker 11 ODBC and JDBC Guide 2004 2010 FileMaker, Inc. All Rights Reserved. FileMaker, Inc. 5201 Patrick Henry Drive Santa Clara, California 95054 FileMaker is a trademark of FileMaker, Inc. registered

More information

Creating Database Tables in Microsoft SQL Server

Creating Database Tables in Microsoft SQL Server Creating Database Tables in Microsoft SQL Server Microsoft SQL Server is a relational database server that stores and retrieves data for multi-user network-based applications. SQL Server databases are

More information

Querying Microsoft SQL Server 2012

Querying Microsoft SQL Server 2012 Course 10774A: Querying Microsoft SQL Server 2012 Length: 5 Days Language(s): English Audience(s): IT Professionals Level: 200 Technology: Microsoft SQL Server 2012 Type: Course Delivery Method: Instructor-led

More information

Tips and Tricks SAGE ACCPAC INTELLIGENCE

Tips and Tricks SAGE ACCPAC INTELLIGENCE Tips and Tricks SAGE ACCPAC INTELLIGENCE 1 Table of Contents Auto e-mailing reports... 4 Automatically Running Macros... 7 Creating new Macros from Excel... 8 Compact Metadata Functionality... 9 Copying,

More information

Microsoft Query, the helper application included with Microsoft Office, allows

Microsoft Query, the helper application included with Microsoft Office, allows 3 RETRIEVING ISERIES DATA WITH MICROSOFT QUERY Microsoft Query, the helper application included with Microsoft Office, allows Office applications such as Word and Excel to read data from ODBC data sources.

More information

Course 10774A: Querying Microsoft SQL Server 2012

Course 10774A: Querying Microsoft SQL Server 2012 Course 10774A: Querying Microsoft SQL Server 2012 About this Course This 5-day instructor led course provides students with the technical skills required to write basic Transact-SQL queries for Microsoft

More information

Course 10774A: Querying Microsoft SQL Server 2012 Length: 5 Days Published: May 25, 2012 Language(s): English Audience(s): IT Professionals

Course 10774A: Querying Microsoft SQL Server 2012 Length: 5 Days Published: May 25, 2012 Language(s): English Audience(s): IT Professionals Course 10774A: Querying Microsoft SQL Server 2012 Length: 5 Days Published: May 25, 2012 Language(s): English Audience(s): IT Professionals Overview About this Course Level: 200 Technology: Microsoft SQL

More information

Jet Data Manager 2012 User Guide

Jet Data Manager 2012 User Guide Jet Data Manager 2012 User Guide Welcome This documentation provides descriptions of the concepts and features of the Jet Data Manager and how to use with them. With the Jet Data Manager you can transform

More information

Silect Software s MP Author

Silect Software s MP Author Silect MP Author for Microsoft System Center Operations Manager Silect Software s MP Author User Guide September 2, 2015 Disclaimer The information in this document is furnished for informational use only,

More information

Data Access Guide. BusinessObjects 11. Windows and UNIX

Data Access Guide. BusinessObjects 11. Windows and UNIX Data Access Guide BusinessObjects 11 Windows and UNIX 1 Copyright Trademarks Use restrictions Patents Copyright 2004 Business Objects. All rights reserved. If you find any problems with this documentation,

More information

Chancery SMS 7.5.0 Database Split

Chancery SMS 7.5.0 Database Split TECHNICAL BULLETIN Microsoft SQL Server replication... 1 Transactional replication... 2 Preparing to set up replication... 3 Setting up replication... 4 Quick Reference...11, 2009 Pearson Education, Inc.

More information

Oracle Database 10g Express

Oracle Database 10g Express Oracle Database 10g Express This tutorial prepares the Oracle Database 10g Express Edition Developer to perform common development and administrative tasks of Oracle Database 10g Express Edition. Objectives

More information

A basic create statement for a simple student table would look like the following.

A basic create statement for a simple student table would look like the following. Creating Tables A basic create statement for a simple student table would look like the following. create table Student (SID varchar(10), FirstName varchar(30), LastName varchar(30), EmailAddress varchar(30));

More information

Once the schema has been designed, it can be implemented in the RDBMS.

Once the schema has been designed, it can be implemented in the RDBMS. 2. Creating a database Designing the database schema... 1 Representing Classes, Attributes and Objects... 2 Data types... 5 Additional constraints... 6 Choosing the right fields... 7 Implementing a table

More information

Business Intelligence Tutorial

Business Intelligence Tutorial IBM DB2 Universal Database Business Intelligence Tutorial Version 7 IBM DB2 Universal Database Business Intelligence Tutorial Version 7 Before using this information and the product it supports, be sure

More information

Querying Microsoft SQL Server 20461C; 5 days

Querying Microsoft SQL Server 20461C; 5 days Lincoln Land Community College Capital City Training Center 130 West Mason Springfield, IL 62702 217-782-7436 www.llcc.edu/cctc Querying Microsoft SQL Server 20461C; 5 days Course Description This 5-day

More information

MOC 20461C: Querying Microsoft SQL Server. Course Overview

MOC 20461C: Querying Microsoft SQL Server. Course Overview MOC 20461C: Querying Microsoft SQL Server Course Overview This course provides students with the knowledge and skills to query Microsoft SQL Server. Students will learn about T-SQL querying, SQL Server

More information

How to test and debug an ASP.NET application

How to test and debug an ASP.NET application Chapter 4 How to test and debug an ASP.NET application 113 4 How to test and debug an ASP.NET application If you ve done much programming, you know that testing and debugging are often the most difficult

More information

Errors That Can Occur When You re Running a Report From Tigerpaw s SQL-based System (Version 9 and Above) Modified 10/2/2008

Errors That Can Occur When You re Running a Report From Tigerpaw s SQL-based System (Version 9 and Above) Modified 10/2/2008 Errors That Can Occur When You re Running a Report From Tigerpaw s SQL-based System (Version 9 and Above) Modified 10/2/2008 1 Introduction The following is an explanation of some errors you might encounter

More information

How To Create A Table In Sql 2.5.2.2 (Ahem)

How To Create A Table In Sql 2.5.2.2 (Ahem) Database Systems Unit 5 Database Implementation: SQL Data Definition Language Learning Goals In this unit you will learn how to transfer a logical data model into a physical database, how to extend or

More information

Oracle Database 10g: Introduction to SQL

Oracle Database 10g: Introduction to SQL Oracle University Contact Us: 1.800.529.0165 Oracle Database 10g: Introduction to SQL Duration: 5 Days What you will learn This course offers students an introduction to Oracle Database 10g database technology.

More information

MyOra 3.0. User Guide. SQL Tool for Oracle. Jayam Systems, LLC

MyOra 3.0. User Guide. SQL Tool for Oracle. Jayam Systems, LLC MyOra 3.0 SQL Tool for Oracle User Guide Jayam Systems, LLC Contents Features... 4 Connecting to the Database... 5 Login... 5 Login History... 6 Connection Indicator... 6 Closing the Connection... 7 SQL

More information

Chapter 4: Database Design

Chapter 4: Database Design Chapter 4: Chapter 4: Objectives Understand data integrity concepts. Learn how to normalize data. Work with SQL Server s tools for enforcing data integrity. Implement primary and foreign keys. Use Declarative

More information

Business Intelligence Tutorial: Introduction to the Data Warehouse Center

Business Intelligence Tutorial: Introduction to the Data Warehouse Center IBM DB2 Universal Database Business Intelligence Tutorial: Introduction to the Data Warehouse Center Version 8 IBM DB2 Universal Database Business Intelligence Tutorial: Introduction to the Data Warehouse

More information

Manipulating Microsoft SQL Server Using SQL Injection

Manipulating Microsoft SQL Server Using SQL Injection Manipulating Microsoft SQL Server Using SQL Injection Author: Cesar Cerrudo ([email protected]) APPLICATION SECURITY, INC. WEB: E-MAIL: [email protected] TEL: 1-866-9APPSEC 1-212-947-8787 INTRODUCTION

More information

FileMaker 13. ODBC and JDBC Guide

FileMaker 13. ODBC and JDBC Guide FileMaker 13 ODBC and JDBC Guide 2004 2013 FileMaker, Inc. All Rights Reserved. FileMaker, Inc. 5201 Patrick Henry Drive Santa Clara, California 95054 FileMaker and Bento are trademarks of FileMaker, Inc.

More information

MOC 20461 QUERYING MICROSOFT SQL SERVER

MOC 20461 QUERYING MICROSOFT SQL SERVER ONE STEP AHEAD. MOC 20461 QUERYING MICROSOFT SQL SERVER Length: 5 days Level: 300 Technology: Microsoft SQL Server Delivery Method: Instructor-led (classroom) COURSE OUTLINE Module 1: Introduction to Microsoft

More information

AV-005: Administering and Implementing a Data Warehouse with SQL Server 2014

AV-005: Administering and Implementing a Data Warehouse with SQL Server 2014 AV-005: Administering and Implementing a Data Warehouse with SQL Server 2014 Career Details Duration 105 hours Prerequisites This career requires that you meet the following prerequisites: Working knowledge

More information

Querying Microsoft SQL Server Course M20461 5 Day(s) 30:00 Hours

Querying Microsoft SQL Server Course M20461 5 Day(s) 30:00 Hours Área de formação Plataforma e Tecnologias de Informação Querying Microsoft SQL Introduction This 5-day instructor led course provides students with the technical skills required to write basic Transact-SQL

More information

Maintaining Stored Procedures in Database Application

Maintaining Stored Procedures in Database Application Maintaining Stored Procedures in Database Application Santosh Kakade 1, Rohan Thakare 2, Bhushan Sapare 3, Dr. B.B. Meshram 4 Computer Department VJTI, Mumbai 1,2,3. Head of Computer Department VJTI, Mumbai

More information

2 SQL in iseries Navigator

2 SQL in iseries Navigator 2 SQL in iseries Navigator In V4R4, IBM added an SQL scripting tool to the standard features included within iseries Navigator and has continued enhancing it in subsequent releases. Because standard features

More information

Testing Web Applications for SQL Injection Sam Shober [email protected]

Testing Web Applications for SQL Injection Sam Shober SamShober@Hotmail.com Testing Web Applications for SQL Injection Sam Shober [email protected] Abstract: This paper discusses the SQL injection vulnerability, its impact on web applications, methods for pre-deployment and

More information

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Objectives After completing this lesson, you should be able to do the following: List the capabilities of SQL SELECT statements Execute a basic SELECT statement

More information

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle Database: SQL and PL/SQL Fundamentals NEW Oracle University Contact Us: + 38516306373 Oracle Database: SQL and PL/SQL Fundamentals NEW Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training delivers the

More information

Toad for Data Analysts, Tips n Tricks

Toad for Data Analysts, Tips n Tricks Toad for Data Analysts, Tips n Tricks or Things Everyone Should Know about TDA Just what is Toad for Data Analysts? Toad is a brand at Quest. We have several tools that have been built explicitly for developers

More information

Troubleshooting guide for 80004005 errors in Active Server Pages and Microsoft Data Access Components

Troubleshooting guide for 80004005 errors in Active Server Pages and Microsoft Data Access Components Page 1 of 9 Troubleshooting guide for 80004005 errors in Active Server Pages and Microsoft Data Access Components This article was previously published under Q306518 On This Page SUMMARY MORE INFORMATION

More information

Database Servers Tutorial

Database Servers Tutorial Copyright 1995-2010 Esri All rights reserved. Table of Contents A quick tour of the database servers tutorial........................ 3 Exercise 1: Add a database server to the Catalog tree and create

More information

Database Design Patterns. Winter 2006-2007 Lecture 24

Database Design Patterns. Winter 2006-2007 Lecture 24 Database Design Patterns Winter 2006-2007 Lecture 24 Trees and Hierarchies Many schemas need to represent trees or hierarchies of some sort Common way of representing trees: An adjacency list model Each

More information

Teradata SQL Assistant Version 13.0 (.Net) Enhancements and Differences. Mike Dempsey

Teradata SQL Assistant Version 13.0 (.Net) Enhancements and Differences. Mike Dempsey Teradata SQL Assistant Version 13.0 (.Net) Enhancements and Differences by Mike Dempsey Overview SQL Assistant 13.0 is an entirely new application that has been re-designed from the ground up. It has been

More information

Oracle Database: SQL and PL/SQL Fundamentals

Oracle Database: SQL and PL/SQL Fundamentals Oracle University Contact Us: 1.800.529.0165 Oracle Database: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn This course is designed to deliver the fundamentals of SQL and PL/SQL along

More information

Visual Studio.NET Database Projects

Visual Studio.NET Database Projects Visual Studio.NET Database Projects CHAPTER 8 IN THIS CHAPTER Creating a Database Project 294 Database References 296 Scripts 297 Queries 312 293 294 Visual Studio.NET Database Projects The database project

More information

Chapter 6: Physical Database Design and Performance. Database Development Process. Physical Design Process. Physical Database Design

Chapter 6: Physical Database Design and Performance. Database Development Process. Physical Design Process. Physical Database Design Chapter 6: Physical Database Design and Performance Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFadden Robert C. Nickerson ISYS 464 Spring 2003 Topic 23 Database

More information

2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA www.sybex.com

2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA www.sybex.com Essential SQL 2 Essential SQL This bonus chapter is provided with Mastering Delphi 6. It is a basic introduction to SQL to accompany Chapter 14, Client/Server Programming. RDBMS packages are generally

More information

Siemens Teamcenter Oracle -to-sql Server 2008 Migration Guide

Siemens Teamcenter Oracle -to-sql Server 2008 Migration Guide Siemens Teamcenter Oracle -to-sql Server 2008 Migration Guide Microsoft Corporation Published: June 2010 Author: Randy Dyess Solid Quality Mentors Technical Reviewers: Christopher Gill Teamcenter Centers

More information

Setting Up ALERE with Client/Server Data

Setting Up ALERE with Client/Server Data Setting Up ALERE with Client/Server Data TIW Technology, Inc. November 2014 ALERE is a registered trademark of TIW Technology, Inc. The following are registered trademarks or trademarks: FoxPro, SQL Server,

More information

HELP DESK MANUAL INSTALLATION GUIDE

HELP DESK MANUAL INSTALLATION GUIDE Help Desk 6.5 Manual Installation Guide HELP DESK MANUAL INSTALLATION GUIDE Version 6.5 MS SQL (SQL Server), My SQL, and MS Access Help Desk 6.5 Page 1 Valid as of: 1/15/2008 Help Desk 6.5 Manual Installation

More information

Optimizing the Performance of the Oracle BI Applications using Oracle Datawarehousing Features and Oracle DAC 10.1.3.4.1

Optimizing the Performance of the Oracle BI Applications using Oracle Datawarehousing Features and Oracle DAC 10.1.3.4.1 Optimizing the Performance of the Oracle BI Applications using Oracle Datawarehousing Features and Oracle DAC 10.1.3.4.1 Mark Rittman, Director, Rittman Mead Consulting for Collaborate 09, Florida, USA,

More information

A Brief Introduction to MySQL

A Brief Introduction to MySQL A Brief Introduction to MySQL by Derek Schuurman Introduction to Databases A database is a structured collection of logically related data. One common type of database is the relational database, a term

More information

QAD Enterprise Applications. Training Guide Demand Management 6.1 Technical Training

QAD Enterprise Applications. Training Guide Demand Management 6.1 Technical Training QAD Enterprise Applications Training Guide Demand Management 6.1 Technical Training 70-3248-6.1 QAD Enterprise Applications February 2012 This document contains proprietary information that is protected

More information

Using ODBC with MDaemon 6.5

Using ODBC with MDaemon 6.5 Using ODBC with MDaemon 6.5 Alt-N Technologies, Ltd 1179 Corporate Drive West, #103 Arlington, TX 76006 Tel: (817) 652-0204 2002 Alt-N Technologies. All rights reserved. Other product and company names

More information

Using SQL Queries in Crystal Reports

Using SQL Queries in Crystal Reports PPENDIX Using SQL Queries in Crystal Reports In this appendix Review of SQL Commands PDF 924 n Introduction to SQL PDF 924 PDF 924 ppendix Using SQL Queries in Crystal Reports The SQL Commands feature

More information

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff D80198GC10 Oracle Database 12c SQL and Fundamentals Summary Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff Level Professional Delivery Method Instructor-led

More information

4 Simple Database Features

4 Simple Database Features 4 Simple Database Features Now we come to the largest use of iseries Navigator for programmers the Databases function. IBM is no longer developing DDS (Data Description Specifications) for database definition,

More information

3 Setting up Databases on a Microsoft SQL 7.0 Server

3 Setting up Databases on a Microsoft SQL 7.0 Server 3 Setting up Databases on a Microsoft SQL 7.0 Server Overview of the Installation Process To set up GoldMine properly, you must follow a sequence of steps to install GoldMine s program files, and the other

More information

Visualization with Excel Tools and Microsoft Azure

Visualization with Excel Tools and Microsoft Azure Visualization with Excel Tools and Microsoft Azure Introduction Power Query and Power Map are add-ins that are available as free downloads from Microsoft to enhance the data access and data visualization

More information

FileMaker 14. ODBC and JDBC Guide

FileMaker 14. ODBC and JDBC Guide FileMaker 14 ODBC and JDBC Guide 2004 2015 FileMaker, Inc. All Rights Reserved. FileMaker, Inc. 5201 Patrick Henry Drive Santa Clara, California 95054 FileMaker and FileMaker Go are trademarks of FileMaker,

More information

Importing and Exporting With SPSS for Windows 17 TUT 117

Importing and Exporting With SPSS for Windows 17 TUT 117 Information Systems Services Importing and Exporting With TUT 117 Version 2.0 (Nov 2009) Contents 1. Introduction... 3 1.1 Aim of this Document... 3 2. Importing Data from Other Sources... 3 2.1 Reading

More information

How-To: MySQL as a linked server in MS SQL Server

How-To: MySQL as a linked server in MS SQL Server How-To: MySQL as a linked server in MS SQL Server 1 Introduction... 2 2 Why do I want to do this?... 3 3 How?... 4 3.1 Step 1: Create table in SQL Server... 4 3.2 Step 2: Create an identical table in MySQL...

More information

Oracle 10g PL/SQL Training

Oracle 10g PL/SQL Training Oracle 10g PL/SQL Training Course Number: ORCL PS01 Length: 3 Day(s) Certification Exam This course will help you prepare for the following exams: 1Z0 042 1Z0 043 Course Overview PL/SQL is Oracle's Procedural

More information

Search help. More on Office.com: images templates

Search help. More on Office.com: images templates Page 1 of 14 Access 2010 Home > Access 2010 Help and How-to > Getting started Search help More on Office.com: images templates Access 2010: database tasks Here are some basic database tasks that you can

More information

SQL Server Database Coding Standards and Guidelines

SQL Server Database Coding Standards and Guidelines SQL Server Database Coding Standards and Guidelines http://www.sqlauthority.com Naming Tables: Stored Procs: Triggers: Indexes: Primary Keys: Foreign Keys: Defaults: Columns: General Rules: Rules: Pascal

More information

Web Application Disassembly with ODBC Error Messages By David Litchfield Director of Security Architecture @stake http://www.atstake.

Web Application Disassembly with ODBC Error Messages By David Litchfield Director of Security Architecture @stake http://www.atstake. Web Application Disassembly with ODBC Error Messages By David Litchfield Director of Security Architecture @stake http://www.atstake.com Introduction This document describes how to subvert the security

More information

Automating Administration with SQL Agent

Automating Administration with SQL Agent Automating Administration with SQL Agent Automating Administration with SQL Agent Objectives Configure SQL Server Agent. Set SQL Server Agent properties. Configure a fail-safe operator. Create operators.

More information

LearnFromGuru Polish your knowledge

LearnFromGuru Polish your knowledge SQL SERVER 2008 R2 /2012 (TSQL/SSIS/ SSRS/ SSAS BI Developer TRAINING) Module: I T-SQL Programming and Database Design An Overview of SQL Server 2008 R2 / 2012 Available Features and Tools New Capabilities

More information

ODBC Chapter,First Edition

ODBC Chapter,First Edition 1 CHAPTER 1 ODBC Chapter,First Edition Introduction 1 Overview of ODBC 2 SAS/ACCESS LIBNAME Statement 3 Data Set Options: ODBC Specifics 15 DBLOAD Procedure: ODBC Specifics 25 DBLOAD Procedure Statements

More information

Choosing a Data Model for Your Database

Choosing a Data Model for Your Database In This Chapter This chapter describes several issues that a database administrator (DBA) must understand to effectively plan for a database. It discusses the following topics: Choosing a data model for

More information

1 Changes in this release

1 Changes in this release Oracle SQL Developer Oracle TimesTen In-Memory Database Support Release Notes Release 4.0 E39883-01 June 2013 This document provides late-breaking information as well as information that is not yet part

More information

Module 1: Getting Started with Databases and Transact-SQL in SQL Server 2008

Module 1: Getting Started with Databases and Transact-SQL in SQL Server 2008 Course 2778A: Writing Queries Using Microsoft SQL Server 2008 Transact-SQL About this Course This 3-day instructor led course provides students with the technical skills required to write basic Transact-

More information

Exploring Microsoft Office Access 2007. Chapter 2: Relational Databases and Multi-Table Queries

Exploring Microsoft Office Access 2007. Chapter 2: Relational Databases and Multi-Table Queries Exploring Microsoft Office Access 2007 Chapter 2: Relational Databases and Multi-Table Queries 1 Objectives Design data Create tables Understand table relationships Share data with Excel Establish table

More information

SQL Server. 1. What is RDBMS?

SQL Server. 1. What is RDBMS? SQL Server 1. What is RDBMS? Relational Data Base Management Systems (RDBMS) are database management systems that maintain data records and indices in tables. Relationships may be created and maintained

More information

2015 OSIsoft TechCon. Optimizing SQL Queries for Performance using PI OLEDB Enterprise

2015 OSIsoft TechCon. Optimizing SQL Queries for Performance using PI OLEDB Enterprise 2015 OSIsoft TechCon Optimizing SQL Queries for Performance using PI OLEDB Enterprise 1 P a g e Table of Contents Contents Table of Contents... 1 Optimizing SQL Queries for Performance using PI OLEDB

More information