create table Customers(
ConsumerId number(13) not null primary key,
CustomerName varchar(50) not null,
Email varchar(255) not null unique check (Email LIKE '%_@__%.__%'),
MobileNo integer(15) not null unique check (MobileNo>0),
UserId int not null constraint check(length(UserId) >= 5),
Password varchar(30) not null,
ConfirmPassword varchar(30) not null,
Status enum('Active', 'Inactive') not null
);
在使用号码时,mysql 工作台上的手机号码也出现超出范围的错误,它显示错误
MobileNo
是integer
,而实际的手机号码通常以0
开头,并且可能包含(
、)
、+
、-
等字符,因此该字段的类型是错误的,显然您已尝试将文本存储为手机号码。
解决办法是
一个简单的解决方案是:
create temporary table customer_temp(
CustomerId int primary key,
MobileNo varchar(50)
);
insert into customer_temp(CustomerId, MobileNo)
select CustomerId, CONVERT(CustomerId, varchar(50))
from Customers;
alter table Customers
change MobileNo MobileNo varchar(50);
update Customers
join customer_temp
on Customers.CustomerId = customer_temp.CustomerId
set Customer.MobileNo = customer_temp.MobileNo;