简体   繁体   中英

an error occured while the batch was being executed

I'm trying to make a simple table in a database.

CREATE TABLE [dbo].[klanten]
(
    [Klant_naam] TEXT NOT NULL PRIMARY KEY, 
    [Klant_adres] TEXT NULL, 
    [klant_gsm] TEXT NULL, 
    [klant_gewicht] INT NOT NULL, 
    [klant_lengte] INT NOT NULL, 
    [klant_klacht] TEXT NOT NULL
)

When I try to update it, the following error pops-up.

错误

As the documentation warns:

ntext , text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead.

So, try this instead:

CREATE TABLE [dbo].[klanten] (
    [Klant_naam] varchar(max) NOT NULL PRIMARY KEY, 
    [Klant_adres] varchar(max)  NULL, 
    [klant_gsm] varchar(max)  NULL, 
    [klant_gewicht] INT NOT NULL, 
    [klant_lengte] INT NOT NULL, 
    [klant_klacht] varchar(max)  NOT NULL
)

Well, this doesn't quite work either, because there is a limit of 900 bytes for index keys. How about using a surrogate key and reasonable column lengths?

CREATE TABLE [dbo].[klanten] (
    Klant_Id int not null identity(1, 1) primary key,
    [Klant_naam] varchar(255) NOT NULL unique, 
    [Klant_adres] varchar(max)  NULL, 
    [klant_gsm] varchar(max)  NULL, 
    [klant_gewicht] INT NOT NULL, 
    [klant_lengte] INT NOT NULL, 
    [klant_klacht] varchar(max)  NOT NULL
);

尝试将“ TEXT”数据类型更改为“ NCHAR()”或任何与此类似的数据。

This error usually occured when you try to update database, but some fields can't be updated. For example, I have 5 fields in a table:

[Id]           INT            IDENTITY (1, 1) NOT NULL,
[Path]         NVARCHAR (MAX) NOT NULL,
[Name]         NVARCHAR (50)  NOT NULL,
[Url]          NVARCHAR (MAX) NULL,
[SecureUrl]    NVARCHAR (MAX) NULL

I've worked for some time with it, and make some records. And some of them have value NULL at [Url]. Suddenly I decide to change table:

[Id]           INT            IDENTITY (1, 1) NOT NULL,
[Path]         NVARCHAR (MAX) NOT NULL,
[Name]         NVARCHAR (50)  NULL,
[Url]          NVARCHAR (MAX) NOT NULL, //!!! HERE A PROBLEM, I ALREADY HAVE NULL RECORDS IN DATA
[SecureUrl]    NVARCHAR (MAX) NULL

Problem is that my data has been made with the old model and it has records with the NULL at [Url], but in new model NULL value can't be at [Url]. So as with new model, old data can't be correct. Thus we have the error when update.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM