Wednesday, June 17, 2009

Advanced Database

Assignment:


1. What is stored procedures?

A stored procedure is a subroutine available to applications accessing a relational database system. Stored procedures (sometimes called a proc, sproc, StoPro, or SP) are actually stored in the database data dictionary.

Typical uses for stored procedures include data validation (integrated into the database) or access control mechanisms. Furthermore, stored procedures are used to consolidate and centralize logic that was originally implemented in applications. Large or complex processing that might require the execution of several SQL statements is moved into stored procedures, and all applications call the procedures only.

Stored procedures are similar to user-defined functions (UDFs). The major difference is that UDFs can be used like any other expression within SQL statements, whereas stored procedures must be invoked using the CALL statement[citation needed]

CALL procedure(…)

or

EXECUTE procedure(…)

Stored procedures can return result sets, i.e. the results of a SELECT statement. Such result sets can be processed using cursors by other stored procedures by associating a result set locator, or by applications. Stored procedures may also contain declared variables for processing data and cursors that allow it to loop through multiple rows in a table. The standard Structured Query Language provides IF, WHILE, LOOP, REPEAT, CASE statements, and more. Stored procedures can receive variables, return results or modify variables and return them, depending on how and where the variable is declared.

2. What is cursors?

In database packages, a 'cursor' comprises a control structure for the successive traversal (and potential processing) of records in a result set.

Database programmers use cursors for processing individual rows returned by the database system for a query. Cursors address an issue many programming languages suffer from: impedance mismatch. Most procedural programming languages do not offer any mechanism for manipulating whole result-sets at once. In this scenario, the application must process rows in a result-set sequentially. Thus one can think of a database cursor as an iterator over the collection of rows in the result set.

Several SQL statements do not require the use of cursors. That includes the INSERT statement, for example, as well as most forms of the DELETE and UPDATE statements. Even a SELECT statement may not involve a cursor if it is used in the variation of SELECT INTO. A SELECT INTO retrieves at most a single row directly into the application.

3. What is embedded SQL?

Embedded SQL is a method of combining the computing power of a programming language and the database manipulation capabilities of SQL. Embedded SQL statements are SQL statements written inline with the program source code of the host language. The embedded SQL statements are parsed by an embedded SQL preprocessor and replaced by host-language calls to a code library. The output from the preprocessor is then compiled by the host compiler. This allows programmers to embed SQL statements in programs written in any number of languages such as: C/C++, COBOL and Fortran.

The ANSI SQL standards committee defined the embedded SQL standard in two steps: a formalism called Module Language was defined, then the embedded SQL standard was derived from Module Language.[1] The SQL standard defines embedding of SQL as embedded SQL and the language in which SQL queries are embedded is referred to as the host language. A popular host language is C. The mixed C and embedded SQL is called Pro*C in Oracle and Sybase database management systems. In the PostgreSQL database management system this precompiler is called ECPG. Other embedded SQL precompilers are Pro*Ada, Pro*COBOL, Pro*FORTRAN, Pro*Pascal, and Pro*PL/I.

4. What is triggers?

A database trigger is procedural code that is automatically executed in response to certain events on a particular table in a database. Triggers can restrict access to specific data, perform logging, or audit data modifications.

There are two classes of triggers, they are either "row triggers" or "statement triggers". Row triggers define an action for every row of a table, while statement triggers occur only once per INSERT, UPDATE, or DELETE statement. Triggers cannot be used to audit data retrieval via SELECT statements.

Each class can be of several types. There are "BEFORE triggers" and "AFTER triggers" which identifies the time of execution of the trigger. There is also an "INSTEAD OF trigger" which is code that gets executed instead of the triggering statement.

There are typically three triggering events that cause triggers to 'fire':

  • INSERT event (as a new record is being inserted into the database).
  • UPDATE event (as a record is being changed).
  • DELETE event (as a record is being deleted).

The trigger is used to automate DML condition process.

The major features of database triggers, and their effects, are:

  • do not accept parameters or arguments (but may store affected-data in temporary tables)
  • cannot perform commit or rollback operations because they are part of the triggering SQL statement (only through autonomous transactions)
  • can cause mutating table errors, if they are poorly written.
Source: http://en.wikipedia.org/wiki/

Sunday, February 15, 2009

Assignment:

SELECT DISTINCT item.name As Item ingredient.name As Ingredient
From madewith as mw, ingredients as i, items as it
Where mw.itemid = it.itemid
And mw.ingredientid = i.ingredientid
And quantity * 3> inventory;



ITEM

INGREDIENT

Garden Salad

Tomato

Water

Water

Fruit Plate

Orange

Fruit Plate

Watermelon

Tuesday, February 3, 2009

Restaurant Database...










Private Sub menu_Click()

Dim data As ADODB.Recordset

Set data = New ADODB.Recordset

If DataEnvironment1.Connection1.State = adstateclose Then

DataEnvironment1.Connection1.Open

End If

If menu.Text = "Chicken Salad" Then

data.Open "SELECT INGREDIENTS.name ,MADEWITH.unit, MADEWITH.quantity FROM MADEWITH,INGREDIENTS WHERE MADEWITH.itemid = 'CHKSD' and INGREDIENTS.ingredientid = MADEWITH.ingredientid;", DataEnvironment1.Connection1, adOpenDynamic, adLockOptimistic

Set DataGrid1.DataSource = data

ElseIf menu.Text = "Fruit Salad" Then

data.Open "SELECT INGREDIENTS.name ,MADEWITH.unit, MADEWITH.quantity FROM MADEWITH,INGREDIENTS WHERE MADEWITH.itemid = 'FRTSD' and INGREDIENTS.ingredientid = MADEWITH.ingredientid;", DataEnvironment1.Connection1, adOpenDynamic, adLockOptimistic

Set DataGrid1.DataSource = data

ElseIf menu.Text = "Fruit Plate" Then

data.Open "SELECT INGREDIENTS.name ,MADEWITH.unit, MADEWITH.quantity FROM MADEWITH,INGREDIENTS WHERE MADEWITH.itemid = 'FRPLT' and INGREDIENTS.ingredientid = MADEWITH.ingredientid;", DataEnvironment1.Connection1, adOpenDynamic, adLockOptimistic

Set DataGrid1.DataSource = data

ElseIf menu.Text = "Garden Salad" Then

data.Open "SELECT INGREDIENTS.name ,MADEWITH.unit, MADEWITH.quantity FROM MADEWITH,INGREDIENTS WHERE MADEWITH.itemid = 'GDNSD' and INGREDIENTS.ingredientid = MADEWITH.ingredientid;", DataEnvironment1.Connection1, adOpenDynamic, adLockOptimistic

Set DataGrid1.DataSource = data

ElseIf menu.Text = "Millenium Salad" Then

data.Open "SELECT INGREDIENTS.name ,MADEWITH.unit, MADEWITH.quantity FROM MADEWITH,INGREDIENTS WHERE MADEWITH.itemid = 'MILSD' and INGREDIENTS.ingredientid = MADEWITH.ingredientid;", DataEnvironment1.Connection1, adOpenDynamic, adLockOptimistic

Set DataGrid1.DataSource = data

ElseIf menu.Text = "Soda" Then

data.Open "SELECT INGREDIENTS.name ,MADEWITH.unit, MADEWITH.quantity FROM MADEWITH,INGREDIENTS WHERE MADEWITH.itemid = 'SODA' and INGREDIENTS.ingredientid = MADEWITH.ingredientid;", DataEnvironment1.Connection1, adOpenDynamic, adLockOptimistic

Set DataGrid1.DataSource = data

ElseIf menu.Text = "Water" Then

data.Open "SELECT INGREDIENTS.name ,MADEWITH.unit, MADEWITH.quantity FROM MADEWITH,INGREDIENTS WHERE MADEWITH.itemid = 'WATER' and INGREDIENTS.ingredientid = MADEWITH.ingredientid;", DataEnvironment1.Connection1, adOpenDynamic, adLockOptimistic

Set DataGrid1.DataSource = data

End If

End Sub



























Wednesday, November 12, 2008

All about RDBMS...

What is RDBMS?

Short for relational database management system and pronounced as separate letters, a type of database management system (DBMS) that stores data in the form of related tables. Relational databases are powerful because they require few assumptions about how data is related or how it will be extracted from the database. As a result, the same database can be viewed in many different ways.

An important feature of relational systems is that a single database can be spread across several tables. This differs from flat-file databases, in which each database is self-contained in a single table.

Almost all full-scale database systems are RDBMS's. Small database systems, however, use other designs that provide less flexibility in posing queries.

DBMS store the data into collection of tables, which might be related by common fields (database table columns). RDBMS also provide relational operators to manipulate the data stored into the database tables. Most RDBMS use SQL as database query language.

Edgar Codd introduced the relational database model. Many modern DBMS do not conform to the Codd’s definition of a RDBMS, but nonetheless they are still considered to be RDBMS.

The most popular RDBMS are MS SQL Server, DB2, Oracle and MySQL.

A set of software that enables the user to create, review, update and delete information held in a relational database.

What are some popular RDBMSs which support SQL?

  • Oracle
  • Sybase
  • Microsoft SQL server
  • Informix
  • Ingress
  • DB2
  • Centura SQLBase (bundled with SQLWindows)
  • Sybase SQLAnywhere (bundled with PowerBuilder)
  • Pervasive.SQL (bundled with many accounting packages)
  • Borland Database Engine/InterBase (bundled with Delphi)

What is the history of RDBMSs?

Dr E.F.Codd of IBM published "A Relational Model of Data for Large Shared Data Banks ", in the Communications of the ACM in 1970. This is the mathematically rigorous theoretical base of the relational databases. Subsequently, he published his famous 12 principles of relational databases in "The Relational Approach to Data Base Management: An Overview", at the Third Annual Texas Conference on Computing Systems in 1974.

What are the different kinds of database management systems?

  • Hierarchical
  • Network
  • Relational
  • Object
  • Object-Relational

While hierarchical and network databases are older than relational databases, object and object - relational databases are of relatively recent origin.

What are the features of a hierarchical database?

The main structures used by the hierarchical model are record types and parent-child relationshipstorage and retrieval are very fast, it is difficult to query a hierarchical database, and impossible to build decision support systems based on it. between a parent record type and a child record type. Access to lower level data elements must first access their parents. Relationships are strictly hierarchical in that a record type can participate as child in at most one parent-child relationship type. This restriction makes it difficult to represent a database where numerous relationships exist. While

What are the features of a network database?

The network model assumes a more complex interrelationship (many to many) between data elements. Relationships and access paths are still predetermined and usually fixed but less restrictive. A record type can participate as owner or member in any number of set.