mysqlÊý¾Ý¿âѧϰ±Ê¼ÇÖ®³£ÓòÙ×÷ÃüÁî(Ò»)

2014-11-24 15:47:35 ¡¤ ×÷Õß: ¡¤ ä¯ÀÀ: 2

mysql Êý¾Ý¿âѧϰ±Ê¼ÇÖ®³£ÓòÙ×÷ÃüÁî
1¡¢´´½¨Êý¾Ý¿â www.2cto.com
mysql> create database user;
Query OK, 1 row affected (0.00 sec)
2¡¢Ê¹ÓôËÊý¾Ý¿â
mysql> use user;
Database changed
3¡¢ÔÚ´ËÊý¾Ý¿âÉÏ´´½¨±í
mysql> create table person(
-> id int unsigned not null auto_increment primary key,
-> name varchar(30)
-> );
Query OK, 0 rows affected (0.00 sec)
4¡¢²é¿´´Ëperson±íµÄ±í½á¹¹ www.2cto.com
mysql> desc person;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(30) | YES | | NULL | |
+-------+------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
5¡¢´´½¨person_bak,²¢ÊǴ˱íµÄ±í½á¹¹ÓëpersonÒ»Ñù£¬¼´¸´ÖÆpersonµÄ±í½á¹¹
mysql> create table person_bak like person;
Query OK, 0 rows affected (0.01 sec)
6¡¢Ïòperson±íÖвåÈëÊý¾Ý
mysql> insert into person (name) values ("user1");
Query OK, 1 row affected (0.00 sec)
7¡¢½«person±íÖеÄÊý¾Ý¸´ÖƵ½person_bak±íÖÐ
mysql> insert into person_bak select * from person;
Query OK, 10 rows affected (0.01 sec)
Records: 10 Duplicates: 0 Warnings: 0
8¡¢Ïòperson±íÖд´½¨nameÁеÄË÷Òý
·½·¨Ò»£º
mysql> create index in_name on person (name);
Query OK, 10 rows affected (0.00 sec)
Records: 10 Duplicates: 0 Warnings: 0
·½·¨¶þ£º
mysql> alter table person add index in_name (name);
Query OK, 10 rows affected (0.01 sec)
Records: 10 Duplicates: 0 Warnings: 0
9¡¢²é¿´Ë÷Òý www.2cto.com
mysql> show index from person;
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| person | 0 | PRIMARY | 1 | id | A | 10 | NULL | NULL | | BTREE | |
| person | 1 | in_name | 1 | name | A | NULL | NULL | NULL | YES | BTREE | |
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
2 rows in set (0.01 sec)
10¡¢ÔÚperson±íÖд´½¨Î¨Ò»Ë÷Òý
mysql> alter table person add unique index un_name (name);
Query OK, 10 rows affected (0.01 sec)
Records: 10 Duplicates: 0 Warnings: 0
11¡¢ÐÞ¸ÄÁеÄÊôÐÔ
mysql> alter table person modify name varchar(20);
Query OK, 10 rows affected (0.01 sec)
Records: 10 Duplicates: 0 Warnings: 0
12¡¢Í³¼Æ±íÖеÄÊý¾ÝÊý¾Ý
mysql> select count(*) from person;
+----------+
| count(*) |
+----------+
| 10 |
+----------+
1 row in set (0.00 sec)
13¡¢´´½¨Ò»¸öÊÓͼ
mysql> create view v_person as select * from person;
Query OK, 0 rows affected (0.01 sec)
14¡¢²é¿´ÊÓͼ(ºÍ²é¿´±íµÄÃüÁîÒ»Ñù)
µ±É¾³ý±íÖеÄijÌõ¼Ç¼ʱ£¬ÏàÓ¦µÄ´Ë±í¶ÔÓ¦µÄÊÓͼÖеÄÂú×ãÌõ¼þµÄ¼Ç¼Ҳ½«»á±»É¾³ýµô
mysql> show tables;
+----------------+
| Tables_in_user |
+----------------+
| person |
| person_bak |
| v_person |
+----------------+
3 rows in set (0.00 sec)
15¡¢É¾³ýÊÓͼ
mysql> drop view v_person;
Query OK, 0 ro