Explanation of the Database Creation Code - Computer engineering - C# php asp .Net SAP SQL

Sunday, April 6, 2008

Explanation of the Database Creation Code

Firstly as you have seen at the article from this one we have created 4 tables : report, employee, factory, part to store the datas.
--> Why we use dbms? We use them to store the datas in a tidy fashion. I mean assume that you are storing the entire data in the same file. In this condition you need to read all the file and try to get the data you need to use. Since we want to access the desired datas in an acceptabşe time period we need to use database systems. I think it is clear enough why we created 4 tables(dividing the entire data).

Then, in the code piece

create table report(
report_ssn int not null,
primary key (report_ssn))

We are creating the table report and we are saying that we gone store in this tale te report_ssn in iteger type and it is the primary key of our table.
--> What is primary key? Primary keys are the special fields in the table which are uniquely identifies a data in that table. For instance if i am storing your and my other friends' names ssn_nos and surnames in a table called friends, then i can find out your informations by typing your ssn number since it uniquely identifies you.

In this code piece

create table employee (
ssn int not null,
e_name varchar(20) not null,
salary int not null,
report_ssn int not null,
fac_id int not null,
primary key (ssn),
foreign key (report_ssn)references report(report_ssn))

We are creating the table employee and storing the required datas in the fields. We set our ssn field as primary key and report_ssn field from report table as foreign key.
-->What is foreign key?Foreign keys are used to combine two related tables. I mean if i want to know which employee report whom i combine the tables employee and report with a foreign key. A foreign key can be created if it is a primary key in which table we want to combine and if there is a limitation as at most one!

In this piece of code

alter table employee add
foreign key(fac_id) references factory(fac_id)

We are altering the table amployee. We are adding a foreign key from the table factory to combine two tables.By using the code 'alter table' you can add or delete some fields from the tables as well.

Whit these explanations you can examine the code i have written in the article before:))

Good Luck!!!

No comments: