quinta-feira, 29 de setembro de 2011

Creating a web-site (Sign-up, delete, select existing itens and update) - Part 1

Guys!
I'm developing a tutorial which gives a step-by-step for amateurs developers.
I've considered you have installed and configured your MS Visual Studio 2008 and Sql Server Express 2008.


THE EXERCISE
We will create all the parts of the database, the code, design, and the things which involvs the system.
Look this diagram:

We have two tables: Department and Staff. Don't forget to observe these importants things:
  • One staff just can work in one department, but one department can have "N" staffs.
  • The primary key of the Department is passed to the other table which foreign key.
I think, the first step is to create the tables, the storeds procedures and to review the SQL concepts 


SQL SERVER
Tables
Open your SQL Server and connect using your windows authentication
Now, the first step is to create a database in your system, follow the examples:


Figure 1: Creating a new database (step 1)

Figure 2: Creating a new database (step 2)

Now, we will to create the tables:
Figure 3: Creating a new table (step 1)


TABLE DEPARTMENT
We can't forget to put the cod_depto as identity, observe the Figure 4.

Figure 4: Creating table (step 2)

When you check "Is Identity" the field cod_depto will auto-increment when the user create a new register. That's very important thing, because this do not permit to create a duplicate register.
In the Figure 5, We are creating a new table (department) and setting the cod_depto as "Primary Key". 
Figure 5: Creating table (step 3)


So finally, put the name of the table (Department) and save this table.
Ps: When you set cod_depto as primary key, automatically the SQL Server set the field for not permit nulls. ("IS NOT NULL")


TABLE STAFF
Click the button to create a "New Query".
Here, I will teach you how to create a table using SQL commands. Look bellow:
Figure 6: Creating table using SQL commands

I set cod_func as Primary Key and how you can observe, the field cod_depto is referenced to the same field of the table "Department".

Storeds Procedures
We need to create the storeds procedures because using these, we can make operations in our preview table like: insert, select existing items, delete, update.
Ps: After to create the procs, click in the button "Execute".


TABLE DEPARTMENT
INSERT

DELETE


SELECT


UPDATE


TABLE STAFF
INSERT


DELETE


SELECT


UPDATE
Uffffffffffffffffffff!!!!!!!!!!!!!!!!!!! The SQL part was finished! =D
See you guys in my next post!
In the next post! Tãtãtãtãtãtãtã.... huauhahauhhuaa
We will model the inferface of our project and begin to develop the software code


Best regards \o

Nenhum comentário:

Postar um comentário