Information Technology Reference
In-Depth Information
+
——————————————
+
| users
|
| comments
|
+
——————————————
+
2 rows in set (0.00 sec)
DESCRIBE USERS;
+
————
+
————————
+
———
+
——
+
————
+
—————————
+
| Field | Type
| Null | Key | Default | Extra
|
+
———-
+
———————
+
———
+
——-
+
————
+
—————————
+
| ID
| int(11)
|
| PRI | NULL
|auto_increment |
| FIRST | varchar(255) | YES |
| NULL
|
|
| LAST | varchar(255) | YES |
| NULL
|
|
+
———-
+
———————
+
———
+
——-
+
————
+
—————————
+
3 rows in set (0.15 sec)
DESCRIBE COMMENTS;
+
——————
+
—————————
+
———
+
———
+
—————
+
————
+
| Field
| Type
| Null |
Key | Default |
Extra |
+
——————
+
—————————
+
———
+
———
+
—————
+
————
+
| USERID
| int(11)
| YES |
|
NULL
|
|
| TIME
| timestamp(14) | YES |
|
NULL
|
|
| MESSAGE | text
| YES |
|
NULL
|
|
+
——————
+
—————————
+
———
+
———
+
—————
+
————
+
3 rows in set (0.00 sec)
Now we can enter a few values, first we define some users:
INSERT INTO USERS VALUES (null,'Sam','Lam');
INSERT INTO USERS VALUES (null,'Jean','Green');
Notice the value null in the first field; a value does not need to be provided
here because the field was defined with AUTO_INCREMENT, and the DBMS
takes care of assigning a sequentially increasing number for each new entry.
To see that, we make a simple query:
SELECT * FROM USERS:
+
——
+
———
+
———
+
| ID
| FIRST | LAST
|
+
——
+
———
+
———
+
| 1
| Sam
| Lam
|
| 2
| Jean | Green |
+
+
2 rows in set (0.27 sec)
This operation selects all rows from the table and displays all columns of
each row. See that Sam Lam has been automatically given the ID 1 and Jean
Green has been given the ID 2. When we store their messages, we will use
these ID numbers in place of their names:
——
+
———
+
———
INSERT INTO COMMENTS VALUES (1, null,
(Continued)
Search WWH ::




Custom Search