Introducing MySQL SQL 39 The SHOW TABLES command lists all of the available tables within a given database. To verify that the table was created successfully and to view the various columns, execute the following command: mysql> describe acc; +———-+—————+——+—–+———+——-+ | Field | Type | NULL | Key | Default | Extra | +———-+—————+——+—–+———+——-+ | acc_id | int(11) | | PRI | 0 | | | username | varchar(64) | YES | | NULL | | | password | varchar(64) | YES | | NULL | | | ts | timestamp(14) | YES | | NULL | | +———-+—————+——+—–+———+——-+ 4 rows in set (0.00 sec) You can view the columns and their definitions within a table by issuing the DESCRIBE
command. If you discover a problem with any definition, you can use the ALTER TABLE command. For our example, we are able to verify that the information was created successfully. Inserts With our database and table defined, we need to populate it with sample data. Here s the data that we would like to get into the table: acc_id username password 1034033 jsmith smithy 1034055 jdoe doey 1034067 jthompson james2 1034089 sstanford stanford 1034123 blewis lewis 1034154 ysheets sheets We can place the data in the database table by using the INSERT command. The format of the MySQL INSERT command is: INSERT INTO
VALUES(,, ) We have to issue three INSERT commands to get all of the information into the database. Here s the output from one INSERT: mysql> INSERT INTO acc VALUES(1034033, ‘jsmith’, ’smithy’, now()); Query OK, 1 row affected (0.00 sec) Two more INSERT commands and all of our sample data is in the table. MySQL also includes a command called LOAD DATA, which populates a database table from a properly formatted text file.
Note: If you are looking for good and affordable webspace to host and run your servlet application check Sandzak servlet hosting services
This entry was posted
on Saturday, December 16th, 2006 at 2:23 am and is filed under developing.
You can follow any responses to this entry through the RSS 2.0 feed.
Responses are currently closed, but you can trackback from your own site.