I am working on a query, and have found minimal documentation from Microsoft on the TSQL "FOR BROWSE" option on a select statement.
I have seen FOR BROWSE documented as an option to cursors, but I haven't been able to find any good examples of using this, or reasons to use FOR BROWSE on a SELECT statement.
What are good reasons to use FOR BROWSE in a TSQL SELECT statement?
I am using SQL Server 2008 and 2012.
In SQL procedures, a cursor make it possible to define a result set (a set of data rows) and perform complex logic on a row by row basis. By using the same mechanics, an SQL procedure can also define a result set and return it directly to the caller of the SQL procedure or to a client application.
Search objects in a single SQL database Here, you can either search the object in a specific database. For that, you can browse the database folder and select the required database. Now, enter the object name in the search box and press enter. It searches the object and gives you a result, as shown below.
The SQL SELECT TOP Clause The SELECT TOP clause is used to specify the number of records to return. The SELECT TOP clause is useful on large tables with thousands of records. Returning a large number of records can impact performance. Note: Not all database systems support the SELECT TOP clause.
You can optionally retrieve formal results of a SQL query as XML by specifying the FOR XML clause in the query. The FOR XML clause can be used in top-level queries and in subqueries. The top-level FOR XML clause can be used only in the SELECT statement.
Appending FOR BROWSE to an SQL SELECT statement or using SET NO_BROWSETABLE ON on a SQL Server connection may be required to retrieve more elaborate schema information.
This may be useful if an application interacts directly or indirectly via the ODBC layer with SQL Server because some of the details returned by the ODBC function SQLColAttribute will return an empty string unless the SQL SELECT has the FOR BROWSE appended.
For example, if your C++ app uses libodbc++ and you get a result set from the query SELECT * FROM A, B you will not be able to retrieve the table names of the columns from the ResultSetMetaData object. However, if you add FOR BROWSE, the table names will be populated corretly.
As far as I can tell. It appears to be an interface for implementing optimistic concurrency control within an application where one or more users will be accessing and updating data from the same source at the same time. It also appears to work in conjunction with a compatible front end library (DB-Library). However, it would appear that this is a somewhat deprecated mechanism as you can achieve all of the above without using the "For Browse" statement. This can be further confirmed by the necessity to create two DBPROCESS structures which are the results of the DB-Library (a deprecated C library) call "dbopen".
In addition, browse mode requires two DBPROCESS structures: one for selecting the data and another for updating based on the selected data. src
Here is an example of using a "For Browse" query in conjunction with the DB-Library.
Ultimately, it would be reasonable to conclude that this mechanism still exists for the purpose of backwards-compatibility. So unless you're maintaining a C based client using the DB-Library, I wouldn't worry too much about this sql "for clause".
Some other sources
One more observation
Cursors declared with FOR BROWSE must wait for uncommitted changes (made by anyone, including the cursor owner) only during the OPEN CURSOR operation. After the cursor is open, subsequent changes do not cause the cursor to wait. When a cursor is reopened, it can be blocked by uncommitted changes. src
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With