Sunteți pe pagina 1din 26

Learn SQL with SQLite

Pgina 1

Home - - A2 Databases - - A2 Scripts - - A2 Problems - - AS Hardware - Database Tutorials - - Lazarus Tutorials - - Lazarus - - Linux - -

Learn SQL with SQLite


Version 1 Contents Introduction Preparations CREATE TABLE DROP TABLE Adding Fields INSERT INTO ... VALUES ... SELECT ... FROM ... WHERE Harder Queries Second Table One-to-many relationship Third Table Many-to-many relationship COUNT Function UPDATE, DELETE and ALTER TABLE Save as a database Foreign Key Improvements SQLite Database Browser Full SQL

Top

Introduction SQL
SQL stands for Structured Query Language. It is a text based programming language that lets you create and interrogate databases using database programs such as SQLite or MySQL. If you need help with SQL syntax then the W3 schools website is very helpful - W3schools website

SQLite3
SQLite is a popular, small and fast database management system. It is public domain so you can legally use it at school or home. It will run from a memory stick. It has a command-line user interface, although the SQLite database browser (see the tutorial) offers a well-designed GUI interface. SQLite can be downloaded from as a 'precompiled binary' for Windows, Mac or Linux from the SQLite website.. Although it is public domain it is sponsored by Mozilla and Google.

Top

Preparations Download

http://www.alevel-computing.x10.mx/TutorialSQLite.php

04/04/2013 22:44:16

Learn SQL with SQLite You should download the program and then install it. To install it, double-click on the downloaded folder and extract the compressed files. You should then double-click on the SQLite installer program which will let you create SQLite anywhere you choose, including a memory stick. This all only takes about 2 minutes!

Pgina 2

Run
Many schools do not allow students to access the command prompt. That is not a problem - SQLite can be run simply by double-clicking on the SQLite icon. This creates a database in memory which you can then save (as you will see later in the tutorials). SQLite can also be run at the command prompt in MS-DOS. In that case, by typing SQLite3 my.db at the command prompt, you will create a completely new database called my.db or open the existing one.

Top

CREATE TABLE CREATE TABLE


Type the following into the text file called MyClass.txt that you have just created. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> CREATE TABLE Student (StudentID integer PRIMARY KEY NOT NULL,); >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> This is a perfectly valid SQL command. However it is easier to read if it is written in a less compressed way. Write it like below using the Enter key and tab key. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> CREATE TABLE Student ( StudentID integer PRIMARY KEY NOT NULL, ); >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> All SQLCommands in SQLite end in a semi-colon (;). That is not necessarily true in other SQL programs like MySQL. This particular SQL command will create a table called Student which has one field, StudentID, which will be the primary key. It will store integers. If this field is blank (null) then you can not save the record that is what NOT NULL means.

Loading the table


Save MyClass.txt Open SQLite by either clicking on the SQLite window or typing SQLite3 at the DOS prompt. You should see the output below: $ sqlite3 SQLite version 3.6.10 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> Look at the next two SQLite commands written below. They begin with a fullstop. This means that they are SQLite commands, not SQL. The first command imports the file you have just written into SQLite and runs the command for you. Of course, creating a file has no output. To show that it really has worked, the second command shows you all the tables that have been created. .read MyClass.txt .tables

http://www.alevel-computing.x10.mx/TutorialSQLite.php

04/04/2013 22:44:16

Learn SQL with SQLite Enter the commands into SQLite prompt You can then see that the table has been created from the output below: sqlite> .read MyClass.txt sqlite> .tables Student sqlite> If there is a problem then press .q and you will exit SQLite. Amend MyClass.txt, save it and try again. Notice that if you press up and down arrow you can recycle commands. This saves a lot of work.

Pgina 3

Top

DROP TABLE DROP TABLE


In the SQLite window, press the up arrow until you get the command .read MyClass.txt and press enter sqlite> .read MyClass.txt SQL error near line 1: table Student already exists This error occurs because you are trying to create a table that already exists. Therefore we will first delete the student table by typing DROP TABLE student; .tables to confirm that it really has gone. sqlite> DROP TABLE student; sqlite> .tables sqlite> No tables are there, so now we can reload the file and recreate the tables without errors.

Top

Adding fields More fields


Open MyClass.txt and add three more fields to the table. Each student has a first name, second name and the form group (form) that they are registered in at the start of the day. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> CREATE TABLE Student ( StudentID integer PRIMARY KEY NOT NULL , First VARCHAR(10), Second VARCHAR(10), Form VARCHAR(4) ); >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> VARCHAR is string or text. Make sure that you recycle commands. Go into SQLite and check that the table can be created

http://www.alevel-computing.x10.mx/TutorialSQLite.php

04/04/2013 22:44:16

Learn SQL with SQLite sqlite> .read MyClass.txt sqlite> .tables Student The next SQLite command .schema shows the SQL commands that we have entered so far: sqlite> .schema CREATE TABLE Student ( StudentID integer PRIMARY KEY NOT NULL, First VARCHAR(10), Second VARCHAR(10), Form VARCHAR(4) ); Now delete the table again sqlite> DROP TABLE student; sqlite> .tables Instead of having to delete the tables every time, we will add this to the end of the MyClass.txt file so it now reads >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> CREATE TABLE Student ( StudentID integer PRIMARY KEY NOT NULL, First VARCHAR(10), Second VARCHAR(10), Form VARCHAR(4) ); DROP TABLE student; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>> Ordinarily you wouldn't want to delete what you have just created immediately but it makes sense here.

Pgina 4

SQL instruction or SQLite command?


SQL is a computer language implemented by various programs like SQLite, MySQL and MS Access. It is the same relationship as the Pascal language and Pascal compilers. Commands starting with a dot like .read and .tables and .schema are SQLite commands. If you used a different database program like MySQL they would not be available. (although similar ones would be). Instructions that end in a semi colon like CREATE TABLE, DROP TABLE, INSERT INTO are part of the SQL language. Its syntax is fairly standard everywhere (although not all database programs insist on semi-colons!).

Top

INSERT INTO ... VALUES INSERT INTO . . . VALUES


In the MyClass.txt file we will add some data into the Student table by using the INSERT INTO . . . VALUES command from SQL. Use Copy and Paste! >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> CREATE TABLE Student ( StudentID integer PRIMARY KEY NOT NULL, First VARCHAR(10), Second VARCHAR(10), http://www.alevel-computing.x10.mx/TutorialSQLite.php 04/04/2013 22:44:16

Learn SQL with SQLite Form VARCHAR(4) ); INSERT INTO Student(StudentID,First,Second,Form) VALUES (1,'David','Beckham','13Sc'); INSERT INTO Student(StudentID,First,Second, Form) VALUES (2,'William','Shakespeare','13Pl'); INSERT INTO Student(StudentID,First,Second, Form) VALUES (3,'Elizabeth','Windsor','13Pl'); INSERT INTO Student(StudentID,First,Second, Form) VALUES (4,'Reginald','Dwight','13Sp'); INSERT INTO Student(StudentID,First,Second, Form) VALUES (5,'Albert','Einstein','13Kr'); INSERT INTO Student(StudentID,First,Second, Form) VALUES (6,'Margaret','Simpson','13Kr'); INSERT INTO Student(StudentID,First,Second, Form) VALUES (7,'Michael','Mouse','13Kr'); INSERT INTO Student(StudentID,First,Second, Form) VALUES (8,'Michael','Jagger','13Kr'); INSERT INTO Student(StudentID,First,Second, Form) VALUES (9,'Edison','Arantes','13Sc'); INSERT INTO Student(StudentID,First,Second, Form) VALUES (10,'Madonna','Ciccone','13Wh'); INSERT INTO Student(StudentID,First,Second, Form) VALUES (11,'Stefani','Germanotta','13Wh'); DROP TABLE Student; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> StudentID is the first column and that is the primary key of the Student table so all the values must be different in the first column. The other columns can have repeats - like 'Michael' for instance. Notice that the strings are in quotes and integers are not. Also, there is no need to specify the fields when all of them are required - this is the default situation. Save the file and then run it in SQLite to check for errors. sqlite> .read MyClass.txt sqlite> .tables sqlite>

Pgina 5

Top

SELECT ... FROM ... WHERE SELECT . . . FROM . . . WHERE . . .


So far we have created a table called student and populated it with student data but not been able to see the data. Running queries on a database is done in SQL using the SELECT . . . FROM command. Add this to near the end of your MyClass.txt file >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> SELECT * FROM Student; DROP TABLE Student;

http://www.alevel-computing.x10.mx/TutorialSQLite.php

04/04/2013 22:44:16

Learn SQL with SQLite >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> Now save MyClass.txt, and then run it In SQLite sqlite> .read MyClass.txt 1|David|Beckham|13Sc 2|William|Shakespeare|13Pl 3|Elizabeth|Windsor|13Sp 4|Reginald|Dwight|13Sp 5|Albert|Einstein|13Kr 6|Margaret|Simpson|13Kr 7|Michael|Mouse|13Kr 8|Michael|Jagger|13Kr 9|Fred|Barrett|13Sc 10|Madonna|Ciccone|13Wh 11|Stefani|Germanotta|13Wh Top

Pgina 6

Harder Queries .header and .mode column


We can tidy the output up by using two new SQLite commands at the top of MyClass.txt. You can also see that comments are made using two hyphens . >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >> .headers ON -- This command gives the columns a title .mode column -- this outputs the tables in aligned columns CREATE TABLE Student ( StudentID integer PRIMARY KEY NOT NULL, >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >> Run this in SQLite to get StudentID First Second Form ---------- ---------- ---------- ---------1 David Beckham 13Sc 2 William Shakespear 13Pl 3 Elizabeth Windsor 13Pl 4 Reginald Dwight 13Sp 5 Albert Einstein 13Kr 6 Margaret Simpson 13Kr 7 Michael Mouse 13Kr 8 Michael Jagger 13Kr 9 Fred Barrett 13Sc 10 Madonna Ciccone 13Wh 11 Stefani Germanotta 13Wh

Entering SQL directly in the SQLite window


You can enter Selects directly in the SQLite window. You will need to comment out the DROP tables command in MyClass.txt first though, otherwise the table will be deleted before we query it. You will also need to run DROP TABLE Student; before you reload MyClass.txt. I will stay with running queries from within the script.

http://www.alevel-computing.x10.mx/TutorialSQLite.php

04/04/2013 22:44:16

Learn SQL with SQLite

Pgina 7

SELECT . . . FROM . . . WHERE


Comment out the Select * FROM Student because we don't wan to run that every time >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > --SELECT * FROM Student >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > Then add another two queries >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > SELECT * FROM Student WHERE first = 'Madonna'; SELECT First, Second FROM Student WHERE first LIKE 'M%'; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > You get the output below. sqlite> .read MyClass.txt StudentID First Second Form ---------- ---------- ---------- ---------10 Madonna Ciccone 13Wh First Second ---------- ---------Margaret Simpson Michael Mouse Michael Jagger Madonna Ciccone The first SELECT picks out a particular student. The second SELECT shows just the first and second fields of students whose first name begins with the letter M. The % symbol is the wildcard.

SELECT . . . FROM . . .WHERE . . . (more possibilities)


Comment out all the previous selects and add three more >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> --SELECT * FROM Student; --SELECT * FROM Student WHERE first = 'Madonna'; --SELECT first,second FROM Student WHERE first LIKE 'M%'; SELECT StudentID, first FROM Student WHERE studentID <4; SELECT StudentID, First FROM Student WHERE first BETWEEN 'Elizabeth' AND 'Margaret'; SELECT StudentID, First FROM Student WHERE NOT First = 'Michael'; DROP TABLE Student; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> This gives http://www.alevel-computing.x10.mx/TutorialSQLite.php 04/04/2013 22:44:16

Learn SQL with SQLite

Pgina 8

StudentID First ---------- ---------1 David 2 William 3 Elizabeth StudentID First ---------- ---------3 Elizabeth 6 Margaret 9 Fred 10 Madonna StudentID First ---------- ---------1 David 2 William 3 Elizabeth 4 Reginald 5 Albert 6 Margaret 9 Fred 10 Madonna 11 Stefani The first query gives students with StudentID < 4 The second query gives all the students with first name between the two names in the alphabet (i.e. between E and M) The third query lists everyone who is not called 'Michael'. All the queries use only the two fields StudentID and First

Top

Second Table Second Table


Now we will add a second table called Class which gives the details of the Class that each student is in when they are registered. It has a primary key and 3 fields to do with the class. First comment out ALL queries using .and then add the table definition. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> CREATE TABLE Student ( StudentID integer PRIMARY KEY NOT NULL, First VARCHAR(10), Second VARCHAR(10), Form VARCHAR(4) ); CREATE TABLE Class ( ClassID VARCHAR(4) PRIMARY KEY NOT NULL, Title VARCHAR(10), Secondname VARCHAR(10), Room VARCHAR(4) ); >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> remember to drop the table at the end. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> http://www.alevel-computing.x10.mx/TutorialSQLite.php 04/04/2013 22:44:16

Learn SQL with SQLite DROP TABLE Student; DROP TABLE Class; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> Save the file and then check it is OK in SQLite sqlite> .read MyClass.txt sqlite> .tables sqlite> There are no tables there, because they have both been dropped. Use INSERT to add the following 5 records they could go anywhere in the file the most logical place is after the INSERT commands for the student table. Notice that when you are inserting data into all the fields that there is no need to specify them. We could have done this with Student earlier too. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> INSERT INTO Class VALUES ('13Sc','Miss','Scarlett','CL1'); INSERT INTO Class VALUES ('13Pl','Prof','Plum','CL4'); INSERT INTO Class VALUES ('13Wh','Dr','Who','TD2'); INSERT INTO Class VALUES ('13Ch','Mr','Spock','ST2'); INSERT INTO Class VALUES ('13Kr','Miss','Krabapple','SM3'); >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> Now add three SELECTs to make sure all is well with the table. Then make sure both tables are deleted at the end. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> SELECT * FROM Class; SELECT * FROM Class WHERE room = 'CL4'; SELECT * FROM Class WHERE room = 'CL4' OR room = 'CL1'; DROP TABLE Student; DROP TABLE Class; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> Run the file in SQLite and you get the result of the final select as sqlite> .read MyClass.txt FormID Title Secondname Room ---------- ---------- ---------- ---------13Sc Miss Scarlett CL1 13Pl Prof Plum CL4 13Wh Dr Who TD2 13Ch Mr Spock ST2 13Kr Miss Krabapple SM3 FormID Title Secondname Room ---------- ---------- ---------- ---------13Pl Prof Plum CL4 FormID Title Secondname Room ---------- ---------- ---------- ---------13Sc Miss Scarlett CL1 13Pl Prof Plum CL4 There is a query listing all the classes

Pgina 9

http://www.alevel-computing.x10.mx/TutorialSQLite.php

04/04/2013 22:44:16

Learn SQL with SQLite a query listing one class a query picking out 2 classes Comment out the queries we are finished with them for the moment. Top

Pgina 10

One-to-many relationship One to many relationship


The next task is to link the students to the class that they are in. Each student is a member of one class. Each class is composed of many students. The relationship is therefore one-to-many. The link centres around the Form field of the Student table and the ClassID field of the Class table It is possible to pick out related data from both tables with a query... A suitable query might be to get the student names with their teacher name might be: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> SELECT First, Second, Form, Title, Secondname FROM Student, Class; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> Unfortunately this doesn't work sqlite> .read MyClass.txt First Second Title Secondname ---------- ---------- ---------- ---------David Beckham Miss Scarlett David Beckham Prof Plum David Beckham Dr Who David Beckham Mr Spock David Beckham Miss Krabapple William Shakespear Miss Scarlett William Shakespear Prof Plum William Shakespear Dr Who William Shakespear Mr Spock William Shakespear Miss Krabapple You can see that all students are linked to all classes. Instead you need to use the related field >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> SELECT First, Second, Form, Title, Secondname FROM Student, Class; WHERE Form = ClassID >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> This links the two related fields mentioned ealier. sqlite> .read MyClass.txt First Second Title Secondname ---------- ---------- ---------- ---------David Beckham Miss Scarlett William Shakespear Prof Plum

http://www.alevel-computing.x10.mx/TutorialSQLite.php

04/04/2013 22:44:16

Learn SQL with SQLite Elizabeth Windsor Prof Plum Albert Einstein Miss Krabapple Margaret Simpson Miss Krabapple Michael Mouse Miss Krabapple Michael Jagger Miss Krabapple Fred Barrett Miss Scarlett Madonna Ciccone Dr Who Stefani Germanott Dr Who Which is what we want. "Hooray!!" Top

Pgina 11

Third Table Third Table


The students will study a variety of subjects. We will create the table of subjects. Notice the alternative way of defining the Primary key. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>> CREATE TABLE Subject ( SubjectID VARCHAR(4) NOT NULL, SubjectTitle VARCHAR(10), PRIMARY KEY(SubjectID) ); >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>> Add the Values >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>> INSERT INTO Subject(SubjectID, SubjectTitle) VALUES ('CO', 'Computing'); INSERT INTO Subject(SubjectID, SubjectTitle) VALUES ('EN', 'English'); INSERT INTO Subject(SubjectID, SubjectTitle) VALUES ('FS', 'Film Studies'); INSERT INTO Subject(SubjectID, SubjectTitle) VALUES ('GG', 'Geography'); INSERT INTO Subject(SubjectID, SubjectTitle) VALUES ('MA', 'Maths'); INSERT INTO Subject(SubjectID, SubjectTitle) VALUES ('MT', 'Music Technology') ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>> Don't forget to delete the table at the end >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>> DROP TABLE Student; DROP TABLE Form; DROP TABLE Subject; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>

Using SELECT . . . FROM . . . ORDER BY . . .


Add the three Selects and check them >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>> SELECT * FROM Subject; SELECT * FROM Subject ORDER BY SubjectID;

http://www.alevel-computing.x10.mx/TutorialSQLite.php

04/04/2013 22:44:16

Learn SQL with SQLite SELECT * FROM Subject ORDER BY Title DESC; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>> Here are the results of the 4 queries from SQLite sqlite> .read MyClass.txt SubjectID SubjectTitle ---------- ---------CO Computing EN English FS Film Studi GG Geography MA Maths MT Music Tech SubjectID SubjectTitle ---------- ---------CO Computing EN English FS Film Studi GG Geography MA Maths MT Music Tech SubjectID SubjectTitle ---------- ---------------MT Music Technology MA Maths GG Geography FS Film Studies EN English CO Computing The three queries list the subjects, the subjects in name order, and the subjects in reverse name order. Top

Pgina 12

Many to many relationship Many to many relationship


The next task is to link the subjects to the students. Each subject is studied by many students. Each student studies many subjects. The relationship is therefore many-to-many. Modelling a many-to-many relationship involves linking the two tables using a new table called a link table.

Composite primary key


The tables to be linked are Student and Subject. To create a link table between the two tables, create a new table with just two fields - the primary key from each table. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>> CREATE TABLE StudentSubject ( SubjectID2 VARCHAR(4) NOT NULL, StudentID2 integer NOT NULL, PRIMARY KEY(SubjectID2, StudentID2) ); >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

http://www.alevel-computing.x10.mx/TutorialSQLite.php

04/04/2013 22:44:16

Learn SQL with SQLite >>>>>> There are 2 fields. The primary key is a composite key made from the two fields. Neither field is a key by itself because each studentid can appear more than once in the student id column, and each subjectid can occur more than once in the subjectid column. However no student can be linked to a subject more than once so for instance (2,'GG') can only occur once. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('GG', 1); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('MA', 1); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('MT', 1); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('CO', 2); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('EN', 2); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('FS',2); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('EN', 3); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('GG', 3); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('MA', 3); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('CO', 4); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('FS', 4); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('MT', 4); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('CO', 5); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('EN', 5); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('FS', 5); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('GG', 6); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('MA', 6); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('EN', 7); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('FS', 7); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('CO', 8); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('FS', 8); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('MT', 8); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('CO', 9); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('GG', 9); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('MT', 9); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('CO', 10); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('EN', 10); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('GG', 10); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('MA', 10); INSERT INTO StudentSubject(SubjectID2, StudentID2) VALUES ('FS',11); >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> Neither field is a key by itself because each Studentid can appear more than once in the StudentId column. Similarly each SubjectId can occur more than once in the Subjectid column. However no student can be linked to a subject more than once so for instance (2,'GG') can only occur once. Now we should delete the StudentSubject Table >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>> DROP TABLE Student; DROP TABLE Form; DROP TABLE Subject; DROP TABLE StudentSubject; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>> Check the table with a query >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>> SELECT * FROM StudentSubject; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Pgina 13

http://www.alevel-computing.x10.mx/TutorialSQLite.php

04/04/2013 22:44:16

Learn SQL with SQLite >>>>>>>> Running the script on SQLite gives . . . sqlite> .read MyClass.txt SubjectID2 StudentID2 ---------- ---------GG 1 MA 1 MT 1 CO 2 EN 2 FS 2 EN 3 GG 3 MA 3 CO 4 FS 4 MT 4 CO 5 EN 5 FS 5 GG 6 MA 6 EN 7 FS 7 CO 8 FS 8 MT 8 CO 9 GG 9 MT 9 CO 10 EN 10 GG 10 MA 10 FS 11 If we want a query to pick out student information from the student table and subject information from the subject table then THREE tables are used Student, Subject and the link between the two, StudentSubject. Compare it with the one-to-many relationship. Effectively there is a one-to-many relationship between Student and StudentSubject. There is also a one-to-many relationship between Subject and StudentSubject. That is what is modelled here. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> SELECT StudentID, First, Second, SubjectTitle FROM Student, Subject, StudentSubject WHERE StudentID = StudentID2 AND SubjectID = SubjectID2; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> Run it on SQLite sqlite> .read MyClass.txt StudentID First Second SubjectTitle ---------- ---------- ---------- -----------1 David Beckham Geography 1 David Beckham Maths 1 David Beckham Music Techno 2 William Shakespear Computing 2 William Shakespear English http://www.alevel-computing.x10.mx/TutorialSQLite.php

Pgina 14

04/04/2013 22:44:16

Learn SQL with SQLite 2 William Shakespear Film Studies 3 Elizabeth Windsor English 3 Elizabeth Windsor Geography 3 Elizabeth Windsor Maths 4 Reginald Dwight Computing 4 Reginald Dwight Film Studies 4 Reginald Dwight Music Techno 5 Albert Einstein Computing 5 Albert Einstein English 5 Albert Einstein Film Studies 6 Margaret Simpson Geography 6 Margaret Simpson Maths 7 Michael Mouse English 7 Michael Mouse Film Studies 8 Michael Jagger Computing 8 Michael Jagger Film Studies 8 Michael Jagger Music Techno 9 Fred Barrett Computing 9 Fred Barrett Geography 9 Fred Barrett Music Techno 10 Madonna Ciccone Computing 10 Madonna Ciccone English 10 Madonna Ciccone Geography 10 Madonna Ciccone Maths 11 Stefani Germanotta Film Studies A similar query but based around the subjects >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> SELECT SubjectTitle, First, Second FROM Subject, Student, StudentSubject WHERE StudentID = StudentID2 AND SubjectID = SubjectID2; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> ,p> gives this output sqlite> .read MyClass.txt SubjectTitle First Second ------------ ---------- ----------Computing William Shakespeare Computing Reginald Dwight Computing Albert Einstein Computing Michael Jagger Computing Fred Barrett Computing Madonna Ciccone English William Shakespeare English Elizabeth Windsor English Albert Einstein English Michael Mouse English Madonna Ciccone Film Studies William Shakespeare Film Studies Reginald Dwight Film Studies Albert Einstein Film Studies Michael Mouse Film Studies Michael Jagger Film Studies Stefani Germanotta Geography David Beckham Geography Elizabeth Windsor Geography Margaret Simpson Geography Fred Barrett Geography Madonna Ciccone Maths David Beckham Maths Elizabeth Windsor Maths Margaret Simpson Maths Madonna Ciccone Music Techno David Beckham Music Techno Reginald Dwight http://www.alevel-computing.x10.mx/TutorialSQLite.php

Pgina 15

04/04/2013 22:44:16

Learn SQL with SQLite Music Techno Michael Jagger Music Techno Fred Barrett or a small modification will let you find who studies Computing . . . >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>> SELECT SubjectTitle, First, Second FROM Subject, Student, StudentSubject WHERE StudentID = StudentID2 AND SubjectID = SubjectID2 AND SubjectID = 'CO'; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>> and prove it using SQLite sqlite> .read MyClass.txt SubjectTitle First Second ------------ ---------- ----------Computing William Shakespeare Computing Reginald Dwight Computing Albert Einstein Computing Michael Jagger Computing Fred Barrett Computing Madonna Ciccone

Pgina 16

Foreign Keys
Although the foreign key constraint in not working in this version on SQLite but ideally you should include the foreign key constraints. StudentID2 is a foreign key in StudentSubject (because it is not the primary key of that table but it is a primary key of Student) SubjectID2 is a foreign key in StudentSubject (because it is not the primary key of that table but it is a primary key of Subject) These should be added to the definition of StudentSubject to give CREATE TABLE StudentSubject ( SubjectID VARCHAR(4) NOT NULL, StudentID integer NOT NULL, PRIMARY KEY(SubjectID, StudentID), FOREIGN KEY (StudentID) REFERENCES Student(StudentID), FOREIGN KEY (SubjectID) REFERENCES Subject(SubjectID) ) Top

COUNT function COUNT function


SQL functions do calculations on the data in other fields One such function is COUNT which counts the number of records in a field. This function can then become a separate field in a query. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>> SELECT COUNT(*) FROM Student; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>> which gives

http://www.alevel-computing.x10.mx/TutorialSQLite.php

04/04/2013 22:44:16

Learn SQL with SQLite

Pgina 17

sqlite> .read MyClass.txt COUNT(*) ---------11 and confirms that there are 11 students. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>> SELECT COUNT(Form) FROM Student; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>> which also gives sqlite> .read MyClass.txt COUNT(Form) ---------11 and confirms that there are 11 students.

SELECT . . .FROM . . . GROUP BY . . .


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>> SELECT COUNT(Form) FROM Student GROUP BY Form; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>> This groups the data according to the Form value and works out COUNT out on each group sqlite> .read MyClass.txt COUNT(Form) ----------4 2 2 1 2 You can have more than one column, for example . . . >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> SELECT Form, COUNT(Form) FROM Student GROUP BY Form; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>> which outputs two columns showing the number of students in each form and its name. sqlite> .read MyClass.txt Form COUNT(Form) ---------- ----------13Kr 4 13Pl 2 13Sc 2 http://www.alevel-computing.x10.mx/TutorialSQLite.php 04/04/2013 22:44:16

Learn SQL with SQLite 13Sp 1 13Wh 2 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > SELECT SubjectTitle, COUNT(SubjectID) FROM Subject, StudentSubject WHERE SubjectID = SubjectID2 GROUP BY SubjectID; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > sqlite> .read MyClass.txt Form COUNT(Form) ---------- ----------13Kr 4 13Pl 2 13Sc 2 13Sp 1 13Wh 2 How good is that ? Pretty good! Top

Pgina 18

UPDATE, DELETE and ALTER TABLE ALTER TABLE . . . ADD COLUMN . . .


The next few SQL commands are used to change the database. It makes more sense to enter them dynamically in SQLite window. Comment out the DROP TABLE commands in yout text file Run the text file in with .read MyClass.txt We will add a new field to the Subject Table called ExamBoard which is text. ALTER TABLE Subject ADD ExamBoard VARCHAR(10); SELECT * FROM Subject; You should see the new column (empty). sqlite> SELECT * FROM Subject; SubjectID SubjectTitle ExamBoard ---------- ------------ ---------CO Computing EN English FS Film Studies GG Geography MA Maths MT Music Techno

UPDATE Subject SET ExamBoard = 'AQA' WHERE SubjectTitle = 'Computing'; This will make the ExamBoard column AQA in the Computing row.

SELECT * FROM Subject

http://www.alevel-computing.x10.mx/TutorialSQLite.php

04/04/2013 22:44:16

Learn SQL with SQLite

Pgina 19

Check it has been entered.

sqlite> UPDATE Subject SET ExamBoard = 'AQA' WHERE SubjectTitle = 'Computing'; sqlite> SELECT * FROM Subject; SubjectID SubjectTitle ExamBoard ---------- ------------ ---------CO Computing AQA EN English FS Film Studies GG Geography MA Maths MT Music Techno

Suppose the student called 'Reginald Dwight' leaves the school.

DELETE FROM Student WHERE first = 'Reginald' AND second = 'Dwight'; SELECT * FROM Student

Check he has left the table.

sqlite> DELETE FROM Student WHERE first = 'Reginald' AND second = 'Dwight'; sqlite> SELECT * FROM Student; StudentID First Second Form ---------- ---------- ---------- ---------1 David Beckham 13Sc 2 William Shakespear 13Pl 3 Elizabeth Windsor 13Pl 5 Albert Einstein 13Kr 6 Margaret Simpson 13Kr 7 Michael Mouse 13Kr 8 Michael Jagger 13Kr 9 Fred Barrett 13Sc 10 Madonna Ciccone 13Wh 11 Stefani Germanotta 13Wh

The ExamBoard column is added. The entry for Computing is AQA. Reginald Dwight is missing (StudentID=4). Where has Reg gone? To become a star . . .

http://www.alevel-computing.x10.mx/TutorialSQLite.php

04/04/2013 22:44:16

Learn SQL with SQLite

Pgina 20

Top

Save as a database
Saving the tables as a database file Before you try to save the tables as a database REMOVE the SQLite references from MyClass.txt Make sure the four DROP TABLE commands are commented out. SAVE the file with a DIFFERENT name

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> --.headers ON -- This gives the columns a title --.mode column -- this outputs the tables in aligned columns >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

then

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> --DROP TABLE Student; --DROP TABLE Form; --DROP TABLE Subject; --DROP TABLE StudentSubject; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

First save the text file as MyClassDB.txt. This file is still a file of SQL commands. So we will use the SQLite backup function and create a database file called MyClassDB.db Enter sqlite3 and enter

.backup MyClass.db

Check that you have this file in the folder The database can later be reopened with

.restore MyClassDB.txt

You should look at the database file (Myclass.db not MyClass.txt in a text editor like Notepad. Yuo will see the contents along with lots of 'weird' characters. Spooky.

http://www.alevel-computing.x10.mx/TutorialSQLite.php

04/04/2013 22:44:16

Learn SQL with SQLite

Pgina 21

Top

Foreign Key
Foreign Key When you have a one-to-many relationship between two tables, you can design a SELECT query to extract information from both tables by using the common field. For instance with the Student and Class tables, the common field was the Form column in the Student table and the ClassID column of the Class column. To get a query using both tables you use the common field like this:

SELECT First, Second, Title, Secondname FROM Student, Class WHERE Form=ClassID; This gives a satisfactory answer. However, you can enter new students and give them a form that doesn't exist in the Class table. This is not desirable. We might also try to delete a teacher the Form column - which ideally should not be possible. To prevent both of these, use the foreign key constraint. Form is known as a 'foreign' key within the Student table because it is the primary key of a different (foreign) table. The field is indicated as a foreign key within the Student table with

CREATE TABLE Student ( StudentID integer PRIMARY KEY NOT NULL, First VARCHAR(10), Second VARCHAR(10), Form VARCHAR(4), FOREIGN KEY (Form) REFERENCES Class(ClassID) );

If I try to enter a new student into 13Zz which doesn't exist

sqlite> Insert INTO Student Values(12,'Fred','Jones','13Zz'); sqlite> select * from Student; StudentID First Second Form ---------- ---------- ---------- ---------1 David Beckham 13Sc 2 William Shakespear 13Pl 3 Elizabeth Windsor 13Pl 4 Reginald Dwight 13Sp 5 Albert Einstein 13Kr

http://www.alevel-computing.x10.mx/TutorialSQLite.php

04/04/2013 22:44:16

Learn SQL with SQLite

Pgina 22

6 Margaret Simpson 13Kr 7 Michael Mouse 13Kr 8 Michael Jagger 13Kr 9 Fred Barrett 13Sc 10 Madonna Ciccone 13Wh 11 Stefani Germanotta 13Wh 12 Fred Jones 13Zz

This should not be possible!! Equally we should not be able to remove a teacher sqlite> Delete from Class where Secondname='Krabapple'; sqlite> select * from Class; CLassID Title Secondname Room ---------- ---------- ---------- ---------13Sc Miss Scarlett CL1 13Pl Prof Plum CL4 13Wh Dr Who TD2 13Ch Mr Spock ST2

Eek! This should not be possible!!!

That is correct - the version of SQLite that we are using does not support Foreign key constraints. Nonetheless, you know what should happen. Here is a nice explanation: SQLite Foreign Key The database management system called MySQL does support foreign keys. Top

Improvements
Normalisation This database is not quite normalised. The Class table should be split into two tables Class and Staff. This is because (for instance) Title and Secondname are not strictly dependent on ClassID. This would be a better setup -

CREATE TABLE Class ( FormID VARCHAR(4) PRIMARY KEY NOT NULL, Room VARCHAR(4), StaffMember VARCHAR(2), FOREIGN KEY (StaffMember) REFERENCES Staff(StaffID) );

http://www.alevel-computing.x10.mx/TutorialSQLite.php

04/04/2013 22:44:16

Learn SQL with SQLite

Pgina 23

CREATE TABLE Staff ( StaffID VARCHAR(2) PRIMARY KEY NOT NULL, Title VARCHAR(10), Second VARCHAR(10) );

Lean and mean. :-)

Top

SQLite Database Browser


SQLite Database Browser The SQLite Database Browser software lets you use create SQLite databases, tables and queries through a GUI (Graphical User Interface). It can also accept our text file of SQL commands and convert them into a database that is visible through its GUI which is what we will do next. It is open-source software that can be downloaded from http:// sourceforge.net/projects/sqlitebrowser First, open your MyClassDB.txt file and delete all the SQLite commands. You can tell which they are because they begin with a full-stop (period). Select File/Import/Database From SQL file FileName = 'MyClass.txt' Name the new database as 'MyClass.db Then you can look at database structure modify the database structure run any SQL statements you want for instance insert data create new tables create new databases

Top

Full SQL
CREATE TABLE Student ( StudentID integer PRIMARY KEY NOT NULL, First VARCHAR(10), Second VARCHAR(10), Form VARCHAR(4) ); INSERT INTO Student(StudentID,First,Second,Form) VALUES
http://www.alevel-computing.x10.mx/TutorialSQLite.php 04/04/2013 22:44:16

Learn SQL with SQLite

Pgina 24

(1,'David','Beckham','13Sc'); INSERT INTO Student(StudentID,First,Second, (2,'William','Shakespeare','13Pl'); INSERT INTO Student(StudentID,First,Second, (3,'Elizabeth','Windsor','13Pl'); INSERT INTO Student(StudentID,First,Second, (4,'Reginald','Dwight','13Sp'); INSERT INTO Student(StudentID,First,Second, (5,'Albert','Einstein','13Kr'); INSERT INTO Student(StudentID,First,Second, (6,'Margaret','Simpson','13Kr'); INSERT INTO Student(StudentID,First,Second, (7,'Michael','Mouse','13Kr'); INSERT INTO Student(StudentID,First,Second, (8,'Michael','Jagger','13Kr'); INSERT INTO Student(StudentID,First,Second, (9,'Edison','Arantes','13Sc'); INSERT INTO Student(StudentID,First,Second, (10,'Madonna','Ciccone','13Wh'); INSERT INTO Student(StudentID,First,Second, (11,'Stefani','Germanotta','13Wh');

Form) VALUES Form) VALUES Form) VALUES Form) VALUES Form) VALUES Form) VALUES Form) VALUES Form) VALUES Form) VALUES Form) VALUES

CREATE TABLE Class ( ClassID VARCHAR(4) PRIMARY KEY NOT NULL, Title VARCHAR(10), Secondname VARCHAR(10), Room VARCHAR(4) ); INSERT INTO Class VALUES ('13Sc','Miss','Scarlett','CL1'); INSERT INTO Class VALUES ('13Pl','Prof','Plum','CL4'); INSERT INTO Class VALUES ('13Wh','Dr','Who','TD2'); INSERT INTO Class VALUES ('13Ch','Mr','Spock','ST2'); INSERT INTO Class VALUES ('13Kr','Miss','Krabapple','SM3'); CREATE TABLE Subject ( SubjectID VARCHAR(4) NOT NULL, SubjectTitle VARCHAR(10), PRIMARY KEY(SubjectID) ); INSERT INTO Subject(SubjectID, SubjectTitle) VALUES ('CO', 'Computing');
http://www.alevel-computing.x10.mx/TutorialSQLite.php 04/04/2013 22:44:16

Learn SQL with SQLite

Pgina 25

INSERT INTO Subject(SubjectID, ('EN', 'English'); INSERT INTO Subject(SubjectID, ('FS', 'Film Studies'); INSERT INTO Subject(SubjectID, ('GG', 'Geography'); INSERT INTO Subject(SubjectID, ('MA', 'Maths'); INSERT INTO Subject(SubjectID, ('MT', 'Music Technology');

SubjectTitle) VALUES SubjectTitle) VALUES SubjectTitle) VALUES SubjectTitle) VALUES SubjectTitle) VALUES

CREATE TABLE StudentSubject ( SubjectID2 VARCHAR(4) NOT NULL, StudentID2 integer NOT NULL, PRIMARY KEY(SubjectID2, StudentID2) ); INSERT INTO ('GG', 1); INSERT INTO ('MA', 1); INSERT INTO ('MT', 1); INSERT INTO ('CO', 2); INSERT INTO ('EN', 2); INSERT INTO ('FS', 2); INSERT INTO ('EN', 3); INSERT INTO ('GG', 3); INSERT INTO ('MA', 3); INSERT INTO ('CO', 4); INSERT INTO ('FS', 4); INSERT INTO ('MT', 4); INSERT INTO ('CO', 5); INSERT INTO ('EN', 5); INSERT INTO ('FS', 5); INSERT INTO ('GG', 6); StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES

http://www.alevel-computing.x10.mx/TutorialSQLite.php

04/04/2013 22:44:16

Learn SQL with SQLite

Pgina 26

INSERT INTO ('MA', 6); INSERT INTO ('EN', 7); INSERT INTO ('FS', 7); INSERT INTO ('CO', 8); INSERT INTO ('FS', 8); INSERT INTO ('MT', 8); INSERT INTO ('CO', 9); INSERT INTO ('GG', 9); INSERT INTO ('MT', 9); INSERT INTO ('CO', 10); INSERT INTO ('EN', 10); INSERT INTO ('GG', 10); INSERT INTO ('MA', 10); INSERT INTO ('FS',11);

StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES StudentSubject(SubjectID2, StudentID2) VALUES

http://www.alevel-computing.x10.mx/TutorialSQLite.php

04/04/2013 22:44:16

S-ar putea să vă placă și