由于某些未知原因导致意外错误

问题描述 投票:0回答:1
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 工作台上的手机号码也出现超出范围的错误,它显示错误

mysql
1个回答
0
投票

MobileNo
integer
,而实际的手机号码通常以
0
开头,并且可能包含
(
)
+
-
等字符,因此该字段的类型是错误的,显然您已尝试将文本存储为手机号码。

解决办法是

  • 备份您已有的手机号码,或将其保存到临时表中
  • 将手机号码转换为varchar
  • 检查数据是否损坏并根据您的备份进行解决

一个简单的解决方案是:

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;
© www.soinside.com 2019 - 2024. All rights reserved.