Failed to execute query. Error: String or binary data would be truncated in table xdbo.user_info', column 'uid'
Failed to execute query. Error: String or binary data would be truncated in table xdbo.user_info', column 'uid'
我在 Azure 上的 SQL 服务器数据库中插入值时遇到问题,出现以下错误:
Failed to execute query. Error: String or binary data would be truncated in table 'dummy_app.dbo.user_info', column 'uid'. Truncated value: 'u'.
The statement has been terminated.
我不明白我哪里错了,我刚刚创建了服务器,我正在尝试试验但无法解决这个问题。
if not exists (select * from sysobjects where name='user_info' and xtype='U')
create table user_info (
uid varchar unique,
name varchar,
email varchar
)
go;
INSERT INTO dbo.user_info(uid, name, email) VALUES('uids', 'name', 'email') go;
创建 table 工作正常,唯一不起作用的是第二个命令 INSERT
我怀疑是你没有给varchar定义长度,默认长度是1。因此,您的价值被截断了。
将 varchar 长度设置为类似 varchar(200) 的值,您应该可以开始了。
这看起来像是 table 过程的 CREATE
部分不包含 varchar
的长度,因此您必须指定一个长度例如varchar(50)
,因为默认是1。请参考link中的官方MS文档,在备注中。
此外,这里是 Azure 中 CREATE TABLE
的语法,可能也会有所帮助。
我在 Azure 上的 SQL 服务器数据库中插入值时遇到问题,出现以下错误:
Failed to execute query. Error: String or binary data would be truncated in table 'dummy_app.dbo.user_info', column 'uid'. Truncated value: 'u'.
The statement has been terminated.
我不明白我哪里错了,我刚刚创建了服务器,我正在尝试试验但无法解决这个问题。
if not exists (select * from sysobjects where name='user_info' and xtype='U')
create table user_info (
uid varchar unique,
name varchar,
email varchar
)
go;
INSERT INTO dbo.user_info(uid, name, email) VALUES('uids', 'name', 'email') go;
创建 table 工作正常,唯一不起作用的是第二个命令 INSERT
我怀疑是你没有给varchar定义长度,默认长度是1。因此,您的价值被截断了。
将 varchar 长度设置为类似 varchar(200) 的值,您应该可以开始了。
这看起来像是 table 过程的 CREATE
部分不包含 varchar
的长度,因此您必须指定一个长度例如varchar(50)
,因为默认是1。请参考link中的官方MS文档,在备注中。
此外,这里是 Azure 中 CREATE TABLE
的语法,可能也会有所帮助。