1 / 10

SQL - introduktion

SQL - introduktion. Create Table Select. Eksempel – VW-Databasen. Lev: [lnr,navn,lby,status] Vare: [vnr, betegn,vaegt,varegr] Bil: [bnr, model,fabrik] Lvb: [lnr,vnr,bnr, kvantum]. Data. SQL: CREATE TABLE. create table lev( lnr varchar(5) NOT NULL,

naomi
Download Presentation

SQL - introduktion

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SQL - introduktion Create Table Select Databaser/SQL-Intro

  2. Eksempel – VW-Databasen • Lev: [lnr,navn,lby,status] • Vare: [vnr, betegn,vaegt,varegr] • Bil: [bnr, model,fabrik] • Lvb: [lnr,vnr,bnr, kvantum] Databaser/SQL-Intro

  3. Data Databaser/SQL-Intro

  4. SQL: CREATE TABLE create table lev( lnr varchar(5) NOT NULL, navn varchar(15) NOT NULL, lby varchar(15) NOT NULL, status int NOT NULL, primary key(lnr) ); create table vare( vnr varchar(5) NOT NULL, betegn varchar(15) NOT NULL, vaegt int NOT NULL, varegr int NOT NULL, primary key (vnr) ); create table bil( bnr varchar(5) NOT NULL, model varchar(15) NOT NULL, fabrik varchar(15) NOT NULL, primary key (bnr) ); Databaser/SQL-Intro

  5. create table lvb( lnr varchar(5) NOT NULL, vnr varchar(5) NOT NULL, bnr varchar(5) NOT NULL, kvantum int NOT NULL, primary key(lnr,vnr,bnr), foreign key(lnr) references lev(lnr), foreign key(vnr) references vare(vnr), foreign key(bnr) references bil(bnr) ); Databaser/SQL-Intro

  6. SQL – række-/søjleudvælgelse • Rækkeudvælgelse: select * from <tabel> where <betingelse> select * from lev where status>2 • Søjleudvælgelse: • select sølje1,sølje2,… • from <tabel> select navn, lby from lev Databaser/SQL-Intro

  7. SQL – operationerne kan kombineres: select navn, lby from lev where status>2 Databaser/SQL-Intro

  8. SQL - Join • Join: • select * • from <tabel1>,<tabel2> • where <tabel1.pk=tabel2.fk> select * from lev,lvb where lev.lnr=lvb.lnr Databaser/SQL-Intro

  9. SQL – operationerne kan kombineres: select navn, lby, vnr from lev,lvb where lev.lnr=lvb.lnr and bnr='b1' Bemærk: strenge i enkelt ’plinger’ – ikke anførselstegn Databaser/SQL-Intro

  10. Øvelser • VW-Databasen Databaser/SQL-Intro

More Related