Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sergey@comp:~$ sqlite3 test_guru
- sqlite> create table categories(id integer primary key autoincrement, title varchar(30));
- sqlite> create table tests(id integer primary key autoincrement, title varchar(30), level integer, categories_id integer not null, foreign key (categories_id) references categories(id));
- sqlite> create table questions (
- ...> id integer primary key autoincrement,
- ...> body text,
- ...> tests_id integer not null,
- ...> foreign key (tests_id) references tests(id)
- ...> );
- sqlite> insert into categories(title) values
- ...> ('HTML'),
- ...> ('CSS'),
- ...> ('RUBY');
- sqlite> insert into tests(title, level, categories_id) values
- ...> ('Basic html', 0, 1),
- ...> ('Basic css', 0, 2),
- ...> ('Basic ruby', 0, 3),
- ...> ('Advanced ruby', 3, 3),
- ...> ('Average ruby', 2, 3);
- sqlite> insert into questions(body, tests_id) values
- ...> ('That is html', 1),
- ...> ('That is css?', 2),
- ...> ('That is ruby?', 3),
- ...> ('That is exeption?', 5),
- ...> ('That is metaprogramming?', 4);
- sqlite> select * from tests where level = 2 or level = 3;
- 4|Advanced ruby|3|3
- 5|Average ruby|2|3
- sqlite> select * from questions where tests_id = 1;
- 1|That is html|1
- sqlite> update tests
- ...> set title = 'Intermediate ruby', level = 2
- ...> where id = 4;
- sqlite> delete from questions where tests_id = 4;
- sqlite> select tests.title, categories.title
- ...> from tests
- ...> join categories
- ...> on tests.categories_id = categories.id;
- Basic html|HTML
- Basic css|CSS
- Basic ruby|RUBY
- Intermediate ruby|RUBY
- Average ruby|RUBY
- sqlite> select questions.body, tests.title
- ...> from questions
- ...> join tests
- ...> on questions.tests_id = tests.id;
- That is html|Basic html
- That is css?|Basic css
- That is ruby?|Basic ruby
- That is exeption?|Average ruby
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement