当前位置: 移动技术网 > IT编程>数据库>Mysql > mysql第五课

mysql第五课

2020年01月03日  | 移动技术网IT编程  | 我要评论

修改表中一行或多行数据:

select*from student;
+----+------+------+
| id | name | ban  |
+----+------+------+
|  1 | yy   | 1913 |
|  7 | ss   | 1923 |
|  8 | 许   | 1913 |
|  9 | 应   | 1913 |
| 10 | aron | 1913 |
+----+------+------+
5 rows in set
update student set name="yiyq"where ban=1913;
query ok, 4 rows affected
rows matched: 4  changed: 4  warnings: 0
检查:select*from student;
+----+------+------+
| id | name | ban  |
+----+------+------+
|  1 | yiyq | 1913 |
|  7 | ss   | 1923 |
|  8 | yiyq | 1913 |
|  9 | yiyq | 1913 |
| 10 | yiyq | 1913 |
+----+------+------+
5 rows in set
删除数据:select*from accout;
+----+------+-------+
| id | name | money |
+----+------+-------+
|  1 | a    |   800 |
|  2 | b    |  1200 |
+----+------+-------+
2 rows in set
delete from accout where name="a";
query ok, 1 row affected
 select*from accout;
+----+------+-------+
| id | name | money |
+----+------+-------+
|  2 | b    |  1200 |
+----+------+-------+
1 row in set
 
创建表时创建索引:
index id;
truncate也是删除数据,但它是删除一个表在重建一个相同的表。
 
 
创建索引:
create [unique/fulltext/spatial] index 索引名 on 表名 (字段名 [(长度)] [asc/desc]);
普通索引什么都不加,
unique:可选参数,表示唯一约束,
fulltext:可选参数,表示全文约束
spatial:可选参数,表示空间约束
 
用alter创建:
alter table 表名 add [unique/fulltext/spatial] index 索引名(字段名[(长度)] [asc/desc]);
普通索引:alter table book add index inter_id(bookid);
 
 
删除索引:
1.alter table 表名 drop index 字段名;
2.drop  index 索引名 on 表名;
 
 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网