mysql> alter table users1 drop truename,drop password,drop age; Query OK, 1 row affected (0.20 sec) Records: 1 Duplicates: 0 Warnings: 0
mysql> delete from provinces where id=3;Query OK, 1 row affected (0.06 sec) mysql> select * from provinces;+----+-------+| id | pname |+----+-------+| 1 | A || 2 | B || 3 | C |+----+-------+3 rows in set (0.00 sec)
mysql> insert provinces(pname)values('A');Query OK, 1 row affected (0.05 sec) mysql> create table users1( -> id smallint unsigned primary key auto_increment, -> username varchar(10) not null, -> pid smallint unsigned, -> foreign key (pid) references provinces(id) on delete cascade);Query OK, 0 rows affected (0.09 sec)
mysql> show indexes from provinces\G;*************************** 1. row *************************** Table: provinces Non_unique: 0 Key_name: PRIMARY Seq_in_index: 1 Column_name: id Collation: A Cardinality: 0 Sub_part: NULL Packed: NULL Null: Index_type: BTREE Comment:Index_comment:1 row in set (0.00 sec)ERROR:No query specified mysql> create table users( -> id smallint unsigned primary key auto_increment, -> username varchar(10) not null, -> pid smallint unsigned, -> foreign key(pid) references provinces (id) -> );Query OK, 0 rows affected (0.12 sec)
mysql> create table provinces( -> id smallint unsigned primary key auto_increment, -> pname varchar(20)not null -> );Query OK, 0 rows affected (0.27 sec)mysql> show create table provinces;+-----------+--------------------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+-----------+--------------------------------------------------------------------------------------------------------------------------------+| provinces | CREATE TABLE `provinces` ( `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `pname` varchar(20) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 |+-----------+--------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec) ![]()
约束以及修改数据表
最新推荐文章于 2021-01-27 19:57:13 发布