CREATE TABLE member( mem_id int primary key auto_increment comment '会员编号', user_name char(20) comment '用户名', sfz char(18) unique comment '身份证号', mobile char(11) comment '手机号码', mem_type char(10) not null default '个人' comment '会员类型,可选值为个人或企业', constraint uq_tel unique(mobile) );里为什么执行ALTER TABLE member DROP PRIMARY KEY;会出现错误
时间: 2023-12-22 21:05:32 浏览: 26
执行ALTER TABLE member DROP PRIMARY KEY;会出现错误,是因为这个member表中的mem_id列是主键,并且是自动增长的,所以不能删除主键约束。如果想要删除主键约束,需要先删除mem_id列的自动增长属性,然后再删除主键约束。可以执行以下语句来删除主键约束:
1. ALTER TABLE member MODIFY COLUMN mem_id INT;
2. ALTER TABLE member DROP PRIMARY KEY;
相关问题
CREATE TABLE member( men_id int primary key auto_increment comment '会员编号', user_name char(20) comment '用户名', sfz char(18) unique comment '身份证号', mobile char(11) comment '手机号码', mem_type char(10) not null defaule '个人' comment '会员类型,可选值为个人或企业', constraint uq_tel unique(mobile) );这段命令有什么问题
这段命令有两个问题:
1. `not null defaule` 应该是 `not null default`,即默认值的拼写有误。
2. `unique` 约束应该在 `mobile` 列后面,而不是在 `sfz` 列后面。
下面是修改后的命令:
```sql
CREATE TABLE member(
men_id int primary key auto_increment comment '会员编号',
user_name char(20) comment '用户名',
sfz char(18) comment '身份证号',
mobile char(11) comment '手机号码',
mem_type char(10) not null default '个人' comment '会员类型,可选值为个人或企业',
unique (mobile),
unique (sfz)
);
```
在上面的命令中,我将 `unique` 约束分别添加到了 `mobile` 和 `sfz` 列上,并且还修改了 `not null default` 的拼写。
`mem_id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT
This is a MySQL data type for defining a column in a table.
`mem_id` is the name of the column.
`int(11)` specifies the data type as an integer with a maximum length of 11 digits.
`NOT NULL` sets the column to be required, meaning a value must be provided for this column when inserting new records.
`PRIMARY KEY` indicates that this column will be used as the primary key for the table, which means it will uniquely identify each record in the table.
`AUTO_INCREMENT` means that the value for this column will be automatically generated by MySQL when a new record is inserted, starting from 1 and incrementing by 1 for each subsequent record.
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)