Showing posts with label Symbiosis. Show all posts
Showing posts with label Symbiosis. Show all posts

Friday, May 1, 2009

Integrity & Security, Normalization, Transaction Management and Concurrent Execution

Constraint can be at column level, table level and even at database level. Examples of column level are not null, check constraint, foreign keys. Example of table level constraint is primary key.
Triggers:
Authorization in SQL:
GRANT ONTO
user list may be a user-id or public-which allows all valid users the privilege granted.
Granting a privilege on a view does not imply granting any privilege on the underlying relations.
Privileges in SQL are the following: select, update, delete, references, usage, all privileges.
REVOKE ONFROM[restrictcascade]
REVOKE SELECT ON branch FROM u1,u2,u3 cascade;
Revocation of a privileges from a user may cause other users also to lose that privilege. This is called cascading of revoke. With restrict REVOKE command fails if cascading revokes are required.
Normalization:
key idea is to reduce the level of redundancy of data, since there are chances to have the multiple version of same data. There is method of quantifying 'how normalized a database is'- Normal Forms(NF).
Any increase in normalization generally involves splitting existing tables into multiple new table, which must be rejoined at the time of query. This can sometime leads to performance issues. So, intentional denormalization is used in some application. Note that these are not the improvements in the relational model, rather they borrow aspects of navigational database and hierarchical database that are speedier than their relational counterparts.
First Normal Form(1NF): A database is said to have in 1NF if no record(row) is repetitive, no field is blank and there is no multiple data in one field.
Second Normal Form(2NF): A database is said to have in 2NF if it is in 1NF and every non key attribute is dependent on primary key. If any column does not dependence on primary key, it should not in that table, rather new table may contain it.
Third Normal Form(3NF): A database is said to have in 3NF if and only if it is in 2NF and transitive dependency is removed.
3NF is widely considered to be sufficient for many application. Most tables reaching 3NF also reaches BCNF.
Steps to perform normalization:
1. Eliminate repeating groups
2. Eliminate redundant data
3. Eliminate columns not dependent on key
4. Isolate independent multiple relationships.

Transaction Management:
TM begins with BEGIN and ends with SQL COMMIT. ROLLBACK is used to rollback to previous consistent state.
Transaction State-
Active- transaction is being executed.
Partially Committed- after the final statement is executed.
Failed- normal execution can no longer proceed.
Aborted-Transaction is stopped and database is being restored to previous consistent state.
Committed- after successful completion.
Recovering from crash:
Steps- Analysis, Redo and Undo(working backwards in the log)

Concurrent Execution:
Problems in concurrent execution
1. Lost Update Problem
2. Temporary Update(or dirty read) Problem
3. Incorrect summary problem
In the precedence graph of any schedule has a cycle then the schedule is not conflict serializable. If it is acyclic then we declare that the schedule is conflict serializable.

Thursday, April 30, 2009

Basics of Database System & DBMS

The DBMS is an interface between DB and users.
User<---->DBMS<---->OS<---->Database.
Database System vs File System
Disadv of file system includes-
1. Dependency of file system on program and vice-versa.
2. Data Redundancy- same piece of data may be stored at more than one place or file.
3. Difficulty in accessing data
4. Data Isolation- data issolated in different file system, may not be retrieved by other programs.
5. Data Integrity issue-
6. Atomicity Problem- It is crucial that whenever a failure occurs, data be restored at consistent state that existed prior to the failure. It is difficult to ensure atomicity on conventional file system.
7. Security Problem- Not much security option is available for conventional file system.

Database system and DBMS overcomes all the above limitations and also allows data abstraction. Data abstraction can be done on physical, logical and view level.

Database Instance- The collection of information at any given point in time is called instance of the database.
The overall design of a database is called Database Schema. Each database may have several schemas that are partitioned according to the level of abstration.
Data Models-It is defined as the structure of the database. It is collection of conceptual tools like for describing data, data relationships, data semantics and consistancy constraints.
Type of data models:
ER Model(Entity relationship), Relational model, object oriented, network data model are few to name.
Database users and administrators-
Users type are naive, application programmers, sophisticated users and specialized user.
Sophisticated users interacts with system without writing application programs. Specialized users are sophisticated users who write specialized DB program that do no fit into tradional data processing framework.
Roles of DBA:
Schema definition, Storage structure and access method definition, Granting of authorization for for data access and Routine management like regular DB backup, ensuring enough free space, monitoring jobs running and ensuring the performance of the database.

Transaction Management:
Transaction management forms the main component of DBMS since each and every query is considered to be a transaction.

SQL

SQL has two streams: DML-Data manipulation language and DDL-Data definition language.

A database may have many tables. These tables may be interlinked with each other using some KEY field, which must be unique, and should not be left blank.This linking has given birth to RDBMS. Other characteristics of RDBMS are Normalization, Concurrent execution of transactions etc.
Data Manipulation Language
The basic structure of SQL contains three clauses: SELECT, FROM and WHERE
Examples:
SELECT fieldname1, fieldname2, fieldname3 FROM tablename;
SELECT * FROM tablename;
For all columns * is used, there should not be any space in tablename and fieldname. They are typed as one word.
SELECT employeeidno FROM employeestatisticstable WHERE salary >=5000;
SELECT employeeidno FROM employeestatisticstable WHERE position='manager';
Text are given in single quotes ' '.
SELECT employeeidno FROM employeestatisticstable WHERE salary >=5000 AND position='staff';
SELECT employeeidno FROM employeestatisticstable WHERE position='manager' OR (salary>50000 AND benefit>10000);
OR is performed before AND. Use paraenthesis if you want otherwise.
IN and BETWEEN are used for range. NOT IN and NOT BETWEEN are also used for opposite result of IN and BETWEEN.
SELECT employeeidno FROM employeestatisticstable WHERE position IN('manager','staff');
SELECT employeeidno FROM employeestatisticstable WHERE position NOT IN('manager','staff');
SELECT employeeidno FROM employeestatisticstable WHERE salary BETWEEN 30000 AND 50000;
SELECT employeeidno FROM employeestatisticstable WHERE salary NOT BETWEEN 30000 AND 50000;
Using LIKE and underscore(_)
SELECT ssn FROM employee WHERE lastname LIKE 'L%';
This gives all names starting with L. If you want names ending with L, use'%L'. If you want R anywhere in the name use '%R%'.
_ matches any character. '___' will match any string with exactly 3 chars. '___' will match any string with at least 3 chars.
SELECT ssn FROM employee WHERE lastname LIKE '___%';
Ordering the display in ascending or descending order.
SELECT fieldname1, fieldname2, fieldname3 FROM tablename ORDER BY fieldname1;
SELECT fieldname1, fieldname2, fieldname3 FROM tablename ORDER BY fieldname1 DESC;

Joins:
A database may have many tables. These tables may be interlinked with each other using some KEY field, which must be unique, and should not be left blank.This linking has given birth to RDBMS. Primary Key is a column or set of columns that uniquely identifies the rest of the data in any given row. A Foriegn Key is a colum in a table where that column is primary key for another table, which means that any data in a foreign key column must have a corresponding data in the other table where that column is primary key. In DBMS speak-this correspondence is known as referential integrity.
For example, there are three tables. AntiqueOwners, Orders and Antiques.
AntiqueOwners
OwnerID OwnerLastName OwnerFirstName

Orders
OwnerID ItemDesired

Antiques
SellerID BuyerID Item

SELECT antiqueowners.ownerlastname, antiqueowners.ownerfirstname FROM antiqueowners, antiques WHERE antiques.buyerid=antiqueowners.ownerid AND antiques.item='chair';

Aggregate Functions- gives sum average min etc for the entire column for matching condition.
SELECT SUM(salary), AVG(salary) FROM employeestatiscticstable;
SELECT MIN(benefits)FROM employeestatiscticstable WHERE position='manager';
SELECT COUNT(*)FROM employeestatiscticstable WHERE position='staff';

Data Definition Language:

CREATE TABLE tablename (column definition list);
CREATE TABLE airport (airport char(4) not null, aname varchar(20), checkin varchar(50));
Copying table:
CREATE TABLE ticket2(ticketno, ticketdate, pid) AS SELECT ticketno, ticketdate, pid FROM ticket;
CREATE TABLE ticket3 AS SELECT * FROM ticket;
DROP TABLE table2;
INSERT INTO is used to insert new rows into a table.
INSERT INTO tablename VALUES(value1, value2,...);
You need to provide value for all columns. If you do not want to then see below.
INSERT INTO tablename (cloumn1, column2,...)VALUES(value1, value2,...);
UPDATE tablename SET columnname=newvalue WHERE columnname=somevalue;
UPDATE person SET lastname='Ratna' WHERE firstname='Anupama';
UPDATE person SET address='ancd', city='Mumbai' WHERE lastname='sharma';
Delete is used to delete the rows from the table.
DELETE FROM tablename WHERE columnname=somevalue;
To delete all the rows in a table
DELETE * FROM tablename;

Friday, April 10, 2009

Web Technologies

Scope of this notes:
webpage design, upload the wesite at some shared webspace available from some ISP. Simple form and multimedia in your website.
Out of scope:
Web server itself, webserver programs like Apache and IIS, web sevrer interaction with DB server. User interation with forms etc. Database query.
Website construction tool:
Adobe Photoshop:
used for photo and images. Like cut a plane from somewhere and put it in other image of cloud etc. File type .psd. This file type contains diiferent layers and other characteristics of Photoshop. Therefore, before using that as an image, one must save it as .jpg.
Micromedia Dreamweaver or Adobe Go Live or Microsoft FrontPage:
Used to create a webpage. Also called as website construction tool. They generate the correct code for the table.Similarly, they will generate code for rollover, image maps etc. Therefore, each line of HTML code writting is not required. Wasting hours in aligning is also not required. These tools do the reverse job. Create table- they will create code automaticlly. Other thing that Dreamweaver do is placing the images made by photoshop at the right aligment, adding text and hyperlink on it, etc.
Web design combines number of disciplines:
Graphics design
Interface design- method of doing things. How page works etc.
Prgramming and scripting- Forms and interactivity. Writing scripts, programs and application for working with database, servers and so on.
Information design- organisation of content and you get it.flowchart and diagram.
HTML Production- using Dreamweaver or Golive.
Multimedia- Using Micromedia Flash and Director
ISP and buy space on the web server:
Hosting / FTP user name: Testing
Hosting / FTP password: password
Website URL: http://www. Testwebsite.com
FTP Site URL: ftp://www. Testwebsite.com
FTP site, username and password are used for site admin. You will have to use FTP client like SmartFTP or Internet explorer for uploading content to the site.
Sound and video clips are stored in one folder. Images are stored in other folder. Other HTML pages are stored in mail folder.
Some Technicalities:
HTMLcodetutorial.com
yourhtmlsource.com
webopedia.coma.ratna
DHTML: eg- changing of image on mouse rollover. Life and fun on the webpage. Supported only on version 4 and above browser.
Javascript: Scripting language developed by Netscape. Client side programming language. Used for form validation etc. Can not be used for anything else outside browser.Can be embedded in the webpage.
ASP:
Active Server pages
Runs inside IIS
IIS is free component of W2k and above.
PWS is a smaller but fully functional version of IIS
Chili and Instant ASP runs without Windows
ASP file is just same as the HTML file except it has .asp extension.
ASP file contains- HTML, XML and scripts. Scripts on ASP file runs on server.
How ASP different from HTML?
When browser requests an HTML file, server returns HTML file. When browser requests ASP file, IIS passes the request to ASP engine. ASP engine reads the ASP file line by line, executes the script in the file. Finally ASP file is retured to the browser as a plain HTML file.
PHP:
Again a scripting language, especially suited for web development and can be embedded into HTML.It is HTML embedded scripting language.
What it does?
Anything! Other CGI program can do. However there are three main things where PHP is used.
Server side scripting
Command line scripting
Writing desktop applications