Heim  >  Artikel  >  Datenbank  >  MySQL入门学习(六)修改和备份、批处理_MySQL

MySQL入门学习(六)修改和备份、批处理_MySQL

WBOY
WBOYOriginal
2016-06-01 13:52:23825Durchsuche

修改和备份、批处理

有时我们要对数据库表和数据库进行修改和删除,可以用如下方法实现:

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 |

+----------+------+------------+-----------+--------+

3、增加记录

前面已经讲过如何增加一条记录,为便于查看,重复与此:

mysql> insert into mytable

-> values ('abc','f','1966-08-17','china','n');

Query OK, 1 row affected (0.05 sec)

查看一下:

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 |

+----------+------+------------+-----------+--------+

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn