Instalar una base de Datos

Debe existir una base de datos previa. Además el módulo DBI deberá estar instalado.

Sigue la descripción SQL de la base de datos que usaremos en las siguietnes secciones:

lhp@nereida:~/Lperl/src/CLASS_DBI$ cat -n example.sql
 1  CREATE TABLE artist (
 2    artistid INTEGER PRIMARY KEY,
 3    name TEXT NOT NULL
 4  );
 5
 6  CREATE TABLE cd (
 7    cdid INTEGER PRIMARY KEY,
 8    artist INTEGER NOT NULL REFERENCES artist(artistid),
 9    title TEXT NOT NULL
10  );
11
12  CREATE TABLE track (
13    trackid INTEGER PRIMARY KEY,
14    cd INTEGER NOT NULL REFERENCES cd(cdid),
15    title TEXT NOT NULL
16  );

Veamos una descripción mas detallada usando el comando .dump :

lhp@nereida:~/Lperl/src/CLASS_DBI$ sqlite3 example.db
SQLite version 3.3.8
Enter ".help" for instructions
sqlite> .dump
BEGIN TRANSACTION;
CREATE TABLE artist (
  artistid INTEGER PRIMARY KEY,
  name TEXT NOT NULL
);
INSERT INTO "artist" VALUES(1, 'Michael Jackson');
INSERT INTO "artist" VALUES(2, 'Eminem');
CREATE TABLE cd (
  cdid INTEGER PRIMARY KEY,
  artist INTEGER NOT NULL REFERENCES artist(artistid),
  title TEXT NOT NULL
);
INSERT INTO "cd" VALUES(1, 1, 'Thriller');
INSERT INTO "cd" VALUES(2, 1, 'Bad');
INSERT INTO "cd" VALUES(3, 2, 'The Marshall Mathers LP');
CREATE TABLE track (
  trackid INTEGER PRIMARY KEY,
  cd INTEGER NOT NULL REFERENCES cd(cdid),
  title TEXT NOT NULL
);
INSERT INTO "track" VALUES(1, 3, 'The Way I Am');
INSERT INTO "track" VALUES(2, 3, 'Stan');
INSERT INTO "track" VALUES(3, 1, 'Billie Jean');
INSERT INTO "track" VALUES(4, 2, 'Leave Me Alone');
INSERT INTO "track" VALUES(5, 2, 'Smooth Criminal');
INSERT INTO "track" VALUES(6, 1, 'Beat It');
INSERT INTO "track" VALUES(7, 2, 'Dirty Diana');
COMMIT;
sqlite>

Casiano Rodríguez León
Licencia de Creative Commons
Principios de Programación Imperativa, Funcional y Orientada a Objetos Una Introducción en Perl/Una Introducción a Perl
por Casiano Rodríguez León is licensed under a Creative Commons Reconocimiento 3.0 Unported License.

Permissions beyond the scope of this license may be available at http://campusvirtual.ull.es/ocw/course/view.php?id=43.
2012-06-19