Mysql中对表字段的增删改查
来源:互联网 发布:java中void意思 编辑:程序博客网 时间:2024/05/28 15:40
mysql中对表字段的增加,修改(修改类型),删除,排序
1.建立一个new 表,表中字段:学号,姓名,年龄。
mysql> create table new (ne_id int(10),ne_name varchar(20),ne_age int(12));
Query OK, 0 rows affected (0.97 sec)
2.表的结构图
mysql> desc new;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| ne_id | int(10) | YES | | NULL | |
| ne_name | varchar(20) | YES | | NULL | |
| ne_age | int(12) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
rows in set (0.01 sec)
3.向new 表中添加一个地址
mysql> alter table new add ne_address varchar(20);
Query OK, 0 rows affected (1.28 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc new;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| ne_id | int(10) | YES | | NULL | |
| ne_name | varchar(20) | YES | | NULL | |
| ne_age | int(12) | YES | | NULL | |
| ne_address | varchar(20) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
rows in set (0.00 sec)
4.将字段名ne_id 改名为 ne_nor
mysql> alter table new change ne_id ne_nor int(10);
Query OK, 0 rows affected (0.22 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc new;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| ne_nor | int(10) | YES | | NULL | |
| ne_name | varchar(20) | YES | | NULL | |
| ne_age | int(12) | YES | | NULL | |
| ne_address | varchar(20) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
5.删除字段ne_nor
mysql> alter table new drop ne_nor;
Query OK, 0 rows affected (1.04 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc new;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| ne_name | varchar(20) | YES | | NULL | |
| ne_age | int(12) | YES | | NULL | |
| ne_address | varchar(20) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
6.修改字段类型:将ne_age 的 int 改为 varchar
mysql> alter table new modify ne_age varchar(20);
Query OK, 0 rows affected (1.34 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc new;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| ne_name | varchar(20) | YES | | NULL | |
| ne_age | varchar(20) | YES | | NULL | |
| ne_address | varchar(20) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)
7.排序
mysql> alter table new modify ne_age varchar(20) after ne_address;
Query OK, 0 rows affected (0.98 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc new;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| ne_name | varchar(20) | YES | | NULL | |
| ne_address | varchar(20) | YES | | NULL | |
| ne_age | varchar(20) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
- Mysql中对表字段的增删改查
- sqlite3中对表字段的增删改查
- 对Access数据库表字段的增删改查
- 对Access数据库表字段的增删改查
- mysql数据库表字段增删改查及索引的增删改查
- PHP 中对MySql 数据库的增删改查
- JDBC对MySQL的增删改查
- php对mysql的增删改查
- 对mysql数据库的增删改查
- MySql对列的增删改查
- jdbc对mysql的增删改查
- oracal增删改表字段
- oracle 增删改表字段
- mysql的对表的增删改查
- 【Java】Java中对Mysql数据库的增删改查、Java的System类
- Mysql的增删改查
- MySQL的增删改查
- Mysql的增删改查
- Oracle 11G R2 在windows server 2008 64位安装时提示:无法在windows "开始"菜单或桌面上创建项
- 循环创建多线程时保证参数的有效性
- 区位码、gb2312、gbk编码之间的关系
- VC2010对Excel的操作
- poj2159
- Mysql中对表字段的增删改查
- json--json2bean
- python备份mysql数据库脚本一枚
- STL Port编译,Windows/Linux
- 编程语言认知
- ASIHTTP 终结者
- Windows 2012安装.NET Framework3.5(0x800F0907)
- 面试问题集锦二
- css box-shadow ie6-8