The Whirlwind Tour: Creating, Accessing, and Dropping a Database

only for RuBoard - do not distribute or recompile

The Whirlwind Tour: Creating, Accessing, and Dropping a Database

Listing 1.1 is a very simple terminal session for creating a database and then a table, entering some rows, and then dropping the database.

Listing 1.1 also serves as an introduction to how code is presented in this book. In some of the code listings (like this one), you see the entire source code with line numbers to the left for reference. Don t type the line numbers in your source.

Listing 1.1 Creating, Accessing, and Dropping a Database
 01 % mysql  02 mysql> show databases;  03 +----------+  04  Database   05 +----------+  06  mysql      07  test       08 +----------+  09 2 rows in set (0.00 sec)  10  11 mysql> create database test_db;  12 Query OK, 1 row affected (0.00 sec)  13 14 mysql> show databases;  15 +----------+  16  Database   17 +----------+  18  mysql      19  test       20  test_db    21 +----------+  22 3 rows in set (0.01 sec)  23  24 mysql> use test_db;  25 Database changed  26 mysql> show tables;  27 Empty set (0.00 sec)  28  29 create table tbl_books_1  30 (  name varchar(30),  31    title varchar(30),  32    year int  33 );  34 Query OK, 0 rows affected (0.00 sec)  35 mysql> describe tbl_books_1;  36 +-------+-------------+------+-----+---------+-------+-----------------------+  37  Field  Type         Null  Key  Default  Extra  Privileges  38 +-------+-------------+------+-----+---------+-------+-----------------------+  39  title  varchar(30)  yes        Null             select,insert,update,references   40  title  varchar(30)  yes        Null             select,insert,update,references   41  title  varchar(30)  yes        Null             select,insert,update,references   42 +-------+-------------+------+-----+---------+-------+-----------------------+  43 3 rows in set (0.00 sec)  44  45 mysql> show tables;  46 +-------------------+  47  Tables_in_test_db   48 +-------------------+  49  tbl_books_1         50 +-------------------+  51 1 row in set (0.00 sec)  52  53 mysql> insert into tbl_books_1 values ('Jack Kerouac', 'On The Road', 1957);  54 Query OK, 1 row affected (0.00 sec)  55  56 mysql> insert into tbl_books_1 values ('Ayn Rand', 'Atlas Shrugged', 1934);  57 Query OK, 1 row affected (0.00 sec)  58  59 mysql> select * from tbl_books_1;  60 +--------------+----------------+------+  61  name          title           year   62 +--------------+----------------+------+  63  Jack Kerouac  On The Road     1957   64  Ayn Rand      Atlas Shrugged  1934   65 +--------------+----------------+------+  66 2 rows in set (0.00 sec)  67  68 mysql> drop database test_db;  69 Query OK, 3 rows affected (0.00 sec)  70  71 mysql> show databases;  72 +----------+  73  Database   74 +----------+  75  mysql      76  test       77 +----------+  78 2 rows in set (0.00 sec)  79  80 mysql> select * from tbl_books_1;  81 ERROR 1146: Table 'test_db.tbl_books_1' doesn't exist  82 mysql> quit  83 Bye  84 % 
only for RuBoard - do not distribute or recompile


MySQL Building User Interfaces
MySQL: Building User Interfaces (Landmark)
ISBN: 073571049X
EAN: 2147483647
Year: 2001
Pages: 119

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net