Presentation is loading. Please wait.

Presentation is loading. Please wait.

Databases in Web Devolvement By Andy Larson Using Microsoft Sever 2000 with ASP Database Integrity Inserting data Stored procedures Views Triggers Tips.

Similar presentations


Presentation on theme: "Databases in Web Devolvement By Andy Larson Using Microsoft Sever 2000 with ASP Database Integrity Inserting data Stored procedures Views Triggers Tips."— Presentation transcript:

1 Databases in Web Devolvement By Andy Larson Using Microsoft Sever 2000 with ASP Database Integrity Inserting data Stored procedures Views Triggers Tips and ticks

2 Integrity Steadfast adherence to a strict moral or ethical code. The state of being unimpaired; soundness. The quality or condition of being whole or undivided; completeness. Source: The American Heritage. Dictionary of the English Language, Fourth Edition Copyright 2000 by Houghton Mifflin Company.

3 Database Integrity or Referential Integrity Is a feature provided by Relational Database Management Systems (RDBMS) that prevents users or applications from entering inconsistent data. Most RDBMS's have various referential integrity rules that you can apply when you create a relationship between two tables.

4 Types 1st Normal Form (1NF) –All the key attributes are defined –There is no repeating data. –All attributes are dependent on the primary key 2NF –It is in 1NF –It does not include partial dependencies 3NF –It is in 2NF –It does not contain transitive dependencies

5 There is also Boyce Codd NF, 4NF, 5NF. These normal forms help eliminate data anomalies. –Update - Having to update the same data in more than one place. –Insert - Cannot insert due to no primary key. –Delete - When information is deleted it may delete more than it should.

6 Inserting Data To put data into a database you have to insert it. This is done by using the insert, or update commands.

7 Inserting insert into pet values('Spot','Cat','4',''); Pet table PetID, PetName, PetType, OwenerId, Updated

8 Updating update Pet set petName = 'Katie' where OwnerId = 1;

9 Stored Procedures Is a query that is stored on the server. It can be called from an ASP page. Values can be passed into it and you can get values from it. One query can be used for many purposes depending on what values are passed into the procedure.

10 Advantages Stored procedures are modular. Stored procedures abstract or separate server-side functions from the client-side. Stored procedures are usually written by database developers or administrators.

11 Creating a Stored Procedure CREATE PROCEDURE PETPROC1 @FName varchar(50), @LName varchar(50) AS SELECT Pet.PetName, PetOwner.First_Name, PetOwner.Last_Name FROM PetOwner, Pet WHERE PetOwner.First_Name = @FName AND PetOwner.Last_Name = @LName AND Pet.OwnerId = PetOwner.OwnerId

12 Views A view is a logical (virtual) table that exists only in memory, yet can be viewed as a real table. A view can be attributes from many tables that are placed into a new logical table. It is very helpful if you have to access the same data from different tables.

13 Creating a View CREATE VIEW Owner_Pet_Names AS SELECT PetOwner.OwnerId, PetOwner.First_Name, PetOwner.Last_Name, Pet.PetName FROM Pet, PetOwner Where Pet.OwnerId = PetOwner.OwnerId

14 Triggers The advantage of a trigger is that it invokes automatically whenever the command, for which it is defined, is issued. A trigger is a kind of stored procedure that executes automatically when you modify a table by using insert, update, or delete.

15 Types of triggers After triggers –Insert –Update –Delete Instead of trigger –Insert –Delete –Update

16 Creating a Trigger create trigger PetTrigger on Pet after update as update Pet set Updated = getdate() where OwnerId = 1;

17 Tips and Tricks Make sure you set up database integrity. Keep attribute names consistent. Create your connection string in a separate ASP file and then import it. Make sure you try your SQL statements before you put them into your asp code.

18 The End Any Questions?


Download ppt "Databases in Web Devolvement By Andy Larson Using Microsoft Sever 2000 with ASP Database Integrity Inserting data Stored procedures Views Triggers Tips."

Similar presentations


Ads by Google