2011年11月10日木曜日

MySQL5.5 テーブルに対するレコードの挿入/更新/削除

①レコードの挿入

mysql> DESCRIBE auth_users;
+---------------+-------------+------+-----+---------+-------+
| Field         | Type        | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| user_name     | varchar(10) | YES  |     | NULL    |       |
| user_password | varchar(10) | YES  |     | NULL    |       |
+---------------+-------------+------+-----+---------+-------+
2 rows in set (0.01 sec)

mysql> insert into auth_users (user_name, user_password) values
    -> ('hanako', 'pass');
Query OK, 1 row affected (0.12 sec)

mysql> select * from auth_users;
+-----------+---------------+
| user_name | user_password |
+-----------+---------------+
| tom       | pass          |
| hanako    | pass          |
+-----------+---------------+
2 rows in set (0.00 sec)

②レコードの更新
mysql> update auth_users
    -> set user_password='pass2'
    -> where user_name = 'tom';
Query OK, 1 row affected (0.14 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from auth_users;
+-----------+---------------+
| user_name | user_password |
+-----------+---------------+
| tom       | pass2         |
| hanako    | pass          |
+-----------+---------------+
2 rows in set (0.00 sec)

③レコードの削除
mysql> delete from auth_users
    -> where user_name = 'tom';
Query OK, 1 row affected (0.09 sec)

mysql> select * from auth_users;
+-----------+---------------+
| user_name | user_password |
+-----------+---------------+
| hanako    | pass          |
+-----------+---------------+
1 row in set (0.00 sec)

0 件のコメント: