Download presentation
Presentation is loading. Please wait.
Published byPhoebe Maxwell Modified over 9 years ago
1
FEN 2014-02-061 Data Definition: CREATE TABLE, ALTER TABLE Data Manipulation: INSERT, UPDATE, DELETE Queries: SELECT SQL: Structured Query Language – Part 1
2
SQL SQL is a realisation of the relational model. SQL is much more than merely queries – it includes: DDL Data Definition Language DML Data Manipulation Language DCL Data Control Language FEN 2014-02-062
3
SQL-Versions SQL has been implemented by many different DBMS-manufactures SQL is to a large extend the same for most DBMSs – close to a de facto standard Standards: SQL86 (SQL1), SQL89 (SQL1½), SQL92 (SQL2), SQL3 (SQL9x/SQL2000? - eventually SQL-99) SQL2 is still the most common standard. SQL-99 (Huge - released in 2002) Now SQL:2003 (partly supported by MS SQL Server 2008,revisions SQL:2008, SQL:2011) Most manufactures have their own extensions (and omissions) to the standard FEN 2014-02-063 For instance: Oracle MySQL MS SQL Server PostgreSQL For instance: Oracle MySQL MS SQL Server PostgreSQL ??? If you are confused – it’s for a good reason. But in practice SQL2 is still most used, the rest is mostly extensions. ??? If you are confused – it’s for a good reason. But in practice SQL2 is still most used, the rest is mostly extensions.
4
Example: MiniBank Table definitions: FEN 2014-02-064 Constraint
5
Example: MiniBank Sample queries: FEN 2014-02-065 Retrieve information about customer number 3: Note: The result is a table (with only one row, not a tuple). Note: The result is a table (with only one row, not a tuple).
6
Example: MiniBank Sample queries: FEN 2014-02-066 Retrieve account number, balance and customer number for accounts with a balance between 1000 and 2000: Note: The result is a table. Note: The result is a table.
7
Example: MiniBank Sample queries: FEN 2014-02-067 Retrieve information about customer Tommy and his accounts: Note: The result is a table (with only one row, not a tuple). Note: The result is a table (with only one row, not a tuple).
8
8 Company: Exercise FEN 2014-02-06 Do Exercise 2, phase 1 and 2 on CompanyExercise.pdf CompanyExercise.pdf
9
9 Company: Relations (PK – FK) FEN 2014-02-06
10
Company on SQL Server Let’s see it work: MS SQL Server Did you note the order of table creation? Did you note the order of inserting sample data? FEN 2014-02-0610
11
11 Company: Exercise FEN 2014-02-06 Do exercise 2, phase 3 of CompanyExercise.pdfCompanyExercise.pdf
12
Company on SQL Server Do we miss a foreign key constraint here? Let’s try to make an error: change mgrssn to a not existing ssn. Why didn’t we add a constraint when the table was created? Solution: ALTER TABLE – let’s try. FEN 2014-02-0612
13
SQL Data Definition Language - Alter Table DROP SCHEMA DROP TABLE ALTER TABLE ADD (column) DROP COLUMN ALTER TABLE DROP CONSTRAINT ADD CONSTRAINT FEN 2014-02-0613
14
14 VW: new database FEN 2014-02-06 Look at this database:..\lektion03 (SQL2)\vwDatabase.pdf..\lektion03 (SQL2)\vwDatabase.pdf Create the database. These scripts may be helpful.scripts
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.