473,382 Members | 1,225 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Cursor, Query, View and Recordset

sci
Could someone help me by answering the questions below?

What's a cursor?
What's difference between Query and View?
Is a RecordSet just part of a table? Can it be part of a query of view?
If the content in a table changed, is it necessary for a old recordset to
renew itself by do "Requery()"?

Thanks for your help!
Jul 20 '05 #1
4 11240
sci (sc****@yahoo.com) writes:
What's a cursor?
As long as we are talking pure SQL only, a cursor is a means to traverse
a result set one row at a time. This is usually a much slower means of
operation, than to process all rows at once in a set-based statement.
But occasionally logic is such that writing a set-based statement is
very complex.

But when you involve clients, the concept of a "cursor" gets a new
meaning, and it confused me for a long time too.

In a client language like Visual Basic, you must process rows (or records
as they usually once they've reach the client) one by one. But this alright,
because at this point all data is in memory.

With a client-side cursor, ADO gets all data to the client, and all
iteration is done there. A server-side part of the iteration is
carried out on the server. This is usually slower and takes up more
resources, but it depends on the kind of cursor. A forward-only
read-only server-side cursor does not really have a cursor on the SQL
side, whereas a updatable keyset cursor has.
What's difference between Query and View?
You could say that a view is a pre-packaged query. A query is something
like SELECT * FROM x WHERE col = 3. "x" here could be a plain table, or
a view.

In fact what the query returns is yet another table, although it is not
materialized as such. Normally though, you call the result of a query
for a result set.
Is a RecordSet just part of a table? Can it be part of a query of view?
The recordset is just the result-set that has traversed to the client
and ADO. The recordset is the result of a query, and it can be a one-to-one
mapping to a table or a view, but it could be any query.
If the content in a table changed, is it necessary for a old recordset to
renew itself by do "Requery()"?


It might be a good idea, but it depends on the logic of the application.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2
sci
Erland Sommarskog <so****@algonet.se> wrote in message
news:Xn**********************@127.0.0.1...
sci (sc****@yahoo.com) writes:
What's a cursor?
As long as we are talking pure SQL only, a cursor is a means to traverse
a result set one row at a time. This is usually a much slower means of
operation, than to process all rows at once in a set-based statement.


Thanks for your explanation! This is very helpful for my learning on this
subject.

While reading your post I still have some other questions. Sorry for my
ignorance.

What's "result set"?
What's "set-based statement"?
Why "set-based statement" is faster than cursor?
What's difference between Query and View?


You could say that a view is a pre-packaged query. A query is something
like SELECT * FROM x WHERE col = 3. "x" here could be a plain table, or
a view.

Since we call a view a pre-packaged query, does this mean that we can
constructed a view and save it in a database for it to be used in a query?
Can a view be either constructed from one table or multiple tables? Is a
view always to be used in a query, or can it be used somewhere else?
Jul 20 '05 #3
On Tue, 30 Sep 2003 05:13:22 GMT, "sci" <sc****@yahoo.com> wrote:
Erland Sommarskog <so****@algonet.se> wrote in message
news:Xn**********************@127.0.0.1...
sci (sc****@yahoo.com) writes:
> What's a cursor?
As long as we are talking pure SQL only, a cursor is a means to traverse
a result set one row at a time. This is usually a much slower means of
operation, than to process all rows at once in a set-based statement.


Thanks for your explanation! This is very helpful for my learning on this
subject.

While reading your post I still have some other questions. Sorry for my
ignorance.

What's "result set"?


Its how we refer to the results of a SELECT statement. eg. SELECT name
FROM employee WHERE name like 'A%';

this will give up all the rows in the table with names starting with
A. This collection of rows is the result set.What's "set-based statement"?
Essentially what I showed above. The table called employees has many
names in it. My statement works on only those starting with A, or the
SET of rows meeting this condition.Why "set-based statement" is faster than cursor?
Because that's what a relational database is designed for.

Tables are indexed, which makes finding records fast. Lets assume that
there are 1000 employees of whom 15 start with A. A cursor is going to
go through the whole table reading every row, while the SQL way is to
use a WHERE clause. Assuming that the name column is indexed SQL
server will be able to find all the names starting with A very
quickly. Assume there is a salary column we want to update by a %age.

UPDATE employee SET salary = salary *1.15 WHERE name LIKE 'A%'

The server uses the index to find the bunch of rows who start with A
and performs the update to only those rows.
> What's difference between Query and View?


You could say that a view is a pre-packaged query. A query is something
like SELECT * FROM x WHERE col = 3. "x" here could be a plain table, or
a view.

Since we call a view a pre-packaged query, does this mean that we can
constructed a view and save it in a database for it to be used in a query?
Can a view be either constructed from one table or multiple tables? Is a
view always to be used in a query, or can it be used somewhere else?


Jul 20 '05 #4
sci (sc****@yahoo.com) writes:
What's "result set"?
Lyndon Hills has already explained this, but permit me to elaborate.
The theory behind relational databases are based on set theory. A table
is a unordered set of data. Thus, the result of a query is also a
table in the logical sense, or a set if you like.
What's "set-based statement"?
A statement which operates on many rows at a time.
Why "set-based statement" is faster than cursor?
I like to supplement Lyndon's answer. He said that tables are fast
because they are indexed, and that is true. However, set-based
statements are faster even if there is no useful index. Say that
we want increaese the salary for all employees with 2%. This can
be done with:

UPDATE employees SET salary = salary * 1.02

The alternative to a set-based statement would be to set up a cursor
and update one row at a time. This would be a lot slower, because there
is a certain overhead to locate a row.

And, as Lyndon so well said: because set-based is what relational
engines are designed for.
Since we call a view a pre-packaged query, does this mean that we can
constructed a view and save it in a database for it to be used in a query?
Can a view be either constructed from one table or multiple tables? A view can be a query that includes many tables - or other views for
that matter. And, yes, a view can be saved in the database for later
queries.
Is a view always to be used in a query, or can it be used somewhere else?


About anything in a database is being used in a query one way or another.
You don't put data in a database, unless you intended to query it in
some way or another.

Normally, you construct views to give users easier access to data. Not
all systems have views, though. The system I work with does not, for
instance. This is because our users access the database from a GUI,
and do not access the database directly.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jim | last post by:
I having a difficult time here trying to figure out what to do here. I need a way to scroll through a recordset and display the results with both forward and backward movement on a web page(PHP...
15
by: Philip Mette | last post by:
I am begginner at best so I hope someone that is better can help. I have a stored procedure that updates a view that I wrote using 2 cursors.(Kind of a Inner Loop) I wrote it this way Because I...
3
by: Ryan Hubbard | last post by:
I would like to run a query from VBA. The query will be one with parameters. Is there a way to run the query and have Access prompt for the values like it does if I where to execute it through...
0
by: totierne | last post by:
comp.databases.ms-access, I want to know how to use Oracle views with session variables in Access. The parameterised views in access, are migrated to views with per session variables. The...
2
by: P B via AccessMonster.com | last post by:
I have a list of 160,000 records with these fields: fname, lname, address, city, state, zip, dob I need to generate a list with all fields where the first initial of lname and the dob are...
6
by: sghi | last post by:
Hi All, I'm new to this group and quite new to access/vba. So, shortly after beginning to write a simple application for my wife, I came across a blocking problem: I need to intercept the sql...
6
by: lesperancer | last post by:
SELECT distinct b.t_orno, b.t_pono FROM tblMonthlyBooking AS b, tblFilterDate, tblFilterDate AS tblFilterDate_1 WHERE (((b.t_yearMonth) Between . And .)); tblMonthlyBooking is a sql server...
6
by: A.M | last post by:
Hi I use a code similar to this to retrieve data from Oracle database: import cx_Oracle
36
by: Liam.M | last post by:
hey guys, I have one last problem to fix, and then my database is essentially done...I would therefore very much appreciate any assistance anyone would be able to provide me with. Currently I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.