cairo university faculty of computers and …lab1 1. introduction: a database: is a collection of...
TRANSCRIPT
1
Cairo University
Faculty of Computers and Information
Information Systems Department
Database I
Lab1
1. Introduction:
A Database: is a collection of related data designed for specific purposes.
A Database Management System (DBMS): A collection of software programs that are used to
define, construct, maintain and manipulate data in databases
File Processing System DBMS (SQL)
1. Isolated files 1. Related files or tables on DB
2. Programs to manipulate each
file
2. It includes programs(MS) to
manipulate DB
3. The file system has no uniform
structure
3. Data stored in a DBMS has a uniform
structure
4. No Query language 4. Query Langauage
5. Programs dependencies;
changes to one file reqiure
changes to application program
5. Programs independencies; changes to
DB reqiure no changes to application
program as the application programs do
not deal directly with DB , it interacts
with DBMS
6. No backup and recovery 6. Backup and recovery exists
SQL : Stands for Structured English Query Language.
Student
DB
Student
program
Results
Faculty
DB
Faculty
Program
Results
Student +
Faculty DB
Student
progra
m
Faculty
Program
Results
Results
DBMS
2
What are the differences between High Level Languages (HLL) and Structured Query
Language (SQL)?
HLL SQL
High level programming languages are
very powerful languages. They abstract the
details of the computer.
The more abstraction the language presents
the more the language became user-
friendly.
High level programming features like more
generic data structures, run-time
interpretation and intermediate code files
often result in slower execution speed,
higher memory consumption and larger
binary size
SQL is considered data-oriented language
which provide powerful ways of
searching and manipulating the relations
that have been described as entity
relationship tables which map one set of
things into other sets.
SQL is also considered as declarative
language, which describes the problem
rather than defining the solution.
It minimize the effort done by the
programs and let them cover only what is
required not how it is going to be done.
HLL has 3 models of execution:
(1) Interpreted
Interpreted languages are read and
then executed directly, with no
compilation stage.
(2) Compiled
Compiled languages are
transformed into an executable
form before running. There are two
types of compilation:
- Intermediate representations
- Machine code generation
(3) Translated
A language may be translated into a
low-level programming language
for which native code compilers are
already widely available. The C
programming language is a
common target for such translators.
SQL is divided into three query
languages:
1. DDL : Data Defintion Language
which used to define the structure
of the DB
2. DML : Data Manipulation
Language which used to
mainpulate and deal with the data
stored inside the DB
3. DCL: Data Control language
which used to control the access
to data on the DB
3
How the data stored in The DB using SQL?
The data stored in the db as tables and for example the figure below shows a simple DB that
includes information about the students and their departments
Where
1.Student_Id, Student-Name, Student_Age, Student_Address,Dept_Id,Dept_Name are
called table fields or attributes
2. Each table must have a Primary Key that uniquiley indentifies
each table record and this PK must stasfies both uniquiness and Not Null condtions
as here Student_Id and Dept_Id
3. In the table student the Dept_id is considered as a Forigen Key
Which represents the relation between student and department
tables, FK can accept null but must have the values that are only included in its
master table(i.e Dept_id can not be equal 5)
Note: if we included Student_Id in the department table as a FK
instead of including Dept_id in the student table will violate the
uniqueness condition for Student_Id as a PK
Student
Student Id (PK)
Student _Name
Student _Age
Student_Address
Dept_id (FK)
Department
Dept Id (PK)
Dept _Name
Dept_Id Dept_Name
1 CS
2 IT
3 IS
4 OR
Column
Row/record
4
2. Introduction on SQL Server 2008
2.1 Installation:
There are several DBMS such as Oracle, MySql, and Microsoft SQL Server our choice. **Steps for SQL Server 2008 Setup …. Will be sent to the students in their materials**
There is no need to make them in the lab. Just inform the students that it will be sent for
them in the materials that I’ll send it to them on their group
2.2 Running SQL Server 2008:
To ensure that our server is working, open “Sql Server Configuration Manager” File All Programs Microsoft Sql Server 2008 R2 Configuration Tools
To manipulate the databases, tables, data … open” Sql Server Management Studio”
File All Programs Microsoft Sql Server 2008 R2 Sql Server Management Studio
5
3. Installing Sample Databases: (we will work on Northwind database) Sample Databases used in this course are “Northwind and Pubs”
*Follow the following steps if you are using MS SQL 2008:
1. Run the executable file “SQL2000SampleDb.msi”
2. Follow the wizard by clicking next till the end
3. A folder will be created on the C:\ drive named “SQL Server 2000 Sample Databases”. *Adding
Sample databases could be done by several methods: (Read the READ ME file in the created
folder for more information)
4. Right click on the Database Folder in the “SQL Server Management Studio” and choose
“Attach”
5. Press on the ADD button to add the MDF file of the Sample Databases
6
6. Perform this process twice, one for the Northwind MDF and the second for Pubs MDF
7. Wait for seconds until installation is finished and click on “Finish”
7
4. How to Access Sample Databases 1. Now open “Microsoft SQL Server Management Studio” and connect
2. Explore on the left side to view the structure of the databases
8
5. Installing and filling MiniUniversity Sample DB 1. Right click on Databases folder in the Management Studio and click create “new Database”
2. Name the Database “MiniUniversity”
3. Open the .sql file named “MiniUniversity Sample Database.sql”
4. Select Database name “MiniUniversity” from the list box in the top left corner of the screen.
5. Press Execute button.