mysql> SELECT name,sex,title FROM mytable,title
-> WHERE name=writer AND name=′abccs′;
+-------+------+-------+
| name | sex | title |
+-------+------+-------+
| abccs | f | a1 |
| abccs | f | a2 |
+-------+------+-------+
mysql> select title,writer,birthaddr,birth from mytable,title
-> where mytable.name=title.writer and title=′a2′;
+-------+--------+-----------+------------+
| title | writer | birthaddr | birth |
+-------+--------+-----------+------------+
| a2 | abccs | china | 1977-07-07 |
+-------+--------+-----------+------------+
修改和备份、批处理 有时我们要对数据库表和数据库进行修改和删除,可以用如下方法实现:
1、增加一列: 如在前面例子中的mytable表中增加一列表示是否单身single: mysql> alter table mytable add column single char(1);
2、修改记录 将abccs的single记录修改为“y”: mysql> update mytable set single=′y′ where name=′abccs′; 现在来看看发生了什么:
mysql> select * from mytable;
+----------+------+------------+-----------+--------+
| name | sex | birth | birthaddr | single |
+----------+------+------------+-----------+--------+
| abccs |f | 1977-07-07 | china | y |
| mary |f | 1978-12-12 | usa | NULL |
| tom |m | 1970-09-02 | usa | NULL |
+----------+------+------------+-----------+--------+
mysql> select * from mytable;
+----------+------+------------+-----------+--------+
| name | sex | birth | birthaddr | single |
+----------+------+------------+-----------+--------+
| abccs |f | 1977-07-07 | china | y |
| mary |f | 1978-12-12 | usa | NULL |
| tom |m | 1970-09-02 | usa | NULL |
| abc |f | 1966-08-17 | china | n |
+----------+------+------------+-----------+--------+
4、删除记录 用如下命令删除表中的一条记录:mysql> delete from mytable where name=′abc′; DELETE从表中删除满足由where给出的条件的一条记录。 再显示一下结果:
mysql> select * from mytable;
+----------+------+------------+-----------+--------+
| name | sex | birth | birthaddr | single |
+----------+------+------------+-----------+--------+
| abccs |f | 1977-07-07 | china | y |
| mary |f | 1978-12-12 | usa | NULL |
| tom |m | 1970-09-02 | usa | NULL |
+----------+------+------------+-----------+--------+
5、删除表: mysql> drop table ****(表1的名字),***表2的名字; 可以删除一个或多个表,小心使用。