Rdbms & SQL Basics
Rdbms & SQL Basics
Rdbms & SQL Basics
What is RDBMS ?
The Relational Database Model:
Relational database management systems, where all data
more feasible.
Advantages of RDBMS
Improved conceptual simplicity Easier database design, implementation, management,
and use
Ad hoc query capability (SQL) Powerful database management system
Disadvantages of RDBMS
Possibility of poor design and implementation
Instance : a table, with rows and columns. #Rows = cardinality, #fields = degree / arity. Schema : specifies name of relation, plus name and type of each column.
E.G. Students(sid: string, name: string, login: string, age: integer, gpa: real).
Faster search performance! Smaller file for table scans. More directed searching. Improved data integrity!
Our Table
user
name
Mike Hillyer
phone1
403-555-1717
phone2
403-555-1919
email1
mike@hoppen.com
email2
mhillyer@mysite.co m
name nickname phone1 phone2 phone3 cell pager address city province postal_code country email1 email2 web_url company department picture notes email_format
Tom Jensen
403-555-1919
403-555-1313
tom@openwin.org
tom@supersite.org
Ray Smith
403-555-1919
403-555-1111
ray@cpma.com
One Solution
user first_name last_name nickname phone cell pager address city province postal_code country web_url department picture notes
first_nam last_nam e e
Mike Mike Tom Tom Ray Ray Hillyer Hillyer Jensen Jensen Smith Smith
phone
403-555-1717 403-555-1919 403-555-1919 403-555-1313 403-555-1919 403-555-1111
email
mike@hoppen.com mhillyer@mysite.com tom@openwin.org tom@supersite.org ray@cpma.com
Multiple rows per user Emails are associated with only one other phone Hard to Search
Satisfying 1NF
user PK user_id first_name last_name nickname address city province postal_code country web_url company department picture notes
phone
email
PK
PK email_id address
Satisfying 2NF
user user PK user_id PK user_id first_name first_name last_name last_name nickname address nickname city address province city postal_code province country postal_code web_url country picture web_url notes picture email_format notes
Satisfying 3NF
user_phone user PK user_id first_name last_name nickname address city province postal_code country web_url picture notes PK,FK1 user_id PK,FK2 phone_id extension PK phone phone_id country_code number type
What is SQL?
When a user wants to get some information from
4/28/2014
Concept of SQL
The user specifies a certain condition. The program will go through all the records in
the database file and select those records that satisfy the condition.(searching).
Statistical information of the data. The result of the query will then be stored in
form of a table.
4/28/2014
4/28/2014
INSERT INTO table_name VALUES (value1, value2,....) You can also specify the columns for which you want to insert data: INSERT INTO table_name (column1, column2,...) VALUES (value1, value2,....)
UPDATE table_name
We want to add a first name to the person with a last name of "Rasmussen": UPDATE Person SET FirstName = 'Nina' WHERE LastName = 'Rasmussen'
LastName Nilsen Rasmussen FirstName Fred Nina Address Kirkegt 56 Storgt 67 City Stavanger
We want to change the address and add the name of the city: UPDATE Person SET Address = 'Stien 12', City = 'Stavanger' WHERE LastName = 'Rasmussen'
LastName Nilsen Rasmussen FirstName Fred Nina Address Kirkegt 56 Stien 12 City Stavanger Stavanger
Delete a Row
LastName Nilsen Rasmussen FirstName Fred Nina Address Kirkegt 56 Stien 12 City Stavanger Stavanger