首页 > 数据库 > MySQL > 正文

mysql中alt er数据表中增加、删除字段与表名修改例子

2019-11-02 14:31:25
字体:
来源:转载
供稿:网友

 alter是非常强大的一个功能我们可以利用alter来修改数据表表名字体名及一些其它的操作了,下面一起来看看mysql中alter数据表中增加、删除字段与表名修改的一个例子.

  

修改删除mysql数据库中的数据内容:

[[email protected] ~]# /usr/local/mysql/bin/mysql -uroot -p'admin' #进入mysql
mysql> create database gbk default character set gbk collate gbk_chinese_ci; #建立一个名字叫做gbk的数据库
mysql> use gbk
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| gbk |
+--------------------+
mysql> show tables;
Empty set (0.00 sec)
mysql> create table test( #建立一个叫做test的数据表
-> id int(4) not null primary key auto_increment,
-> name char(20) not null
-> );
Query OK, 0 rows affected (0.13 sec)

mysql> show tables;
+---------------+
| Tables_in_gbk |
+---------------+
| test |
+---------------+
1 row in set (0.00 sec)
mysql> insert into test(id,name) values(1,'zy'); #插入部分内容
mysql> insert into test(id,name) values(2,'binghe');
mysql> insert into test(id,name) values(3,'zilong');
mysql> insert into test(id,name) values(4,'feng');
mysql> select * from test; #检索整个test表
+----+--------+
| id | name |
+----+--------+
| 1 | zy |
| 2 | binghe |
| 3 | zilong |
| 4 | feng |
+----+--------+
4 rows in set (0.00 sec)
[[email protected] ~]# /usr/local/mysql/bin/mysqldump -uroot -p'admin' -B gbk >/tmp/gbk.sql #备份gbk数据库
mysql> update test set name = 'zy' ; #未定义
mysql> select * from test; #
+----+------+
| id | name |
+----+------+
| 1 | zy |
| 2 | zy |
| 3 | zy |
| 4 | zy |
+----+------+
[[email protected] ~]# /usr/local/mysql/bin/mysql -uroot -p'admin' mysql> use gbk
mysql> select * from test;
+----+--------+
| id | name |
+----+--------+
| 1 | zy |
| 2 | binghe |
| 3 | zilong |
| 4 | feng |
+----+--------+
mysql> update test set name = 'yadianna' where id =1;
mysql> select * from test;
+----+----------+
| id | name |
+----+----------+
| 1 | yadianna |
| 2 | binghe |
| 3 | zilong |
| 4 | feng |
+----+----------+
mysql> update test set id = 999 where name ='yadianna';
mysql>

顺口溜[www.62-6.com/1/marenbaodian/]
select * from test;
+-----+----------+
| id | name |
+-----+----------+
| 2 | binghe |
| 3 | zilong |
| 4 | feng |
| 999 | yadianna |
+-----+----------+
mysql> delete from test where id =999;
mysql> select * from test;
+----+--------+
| id | name |
+----+--------+
| 2 | binghe |
| 3 | zilong |
| 4 | feng |
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表