Error importing modified object into NAV 4.02 SQL

Hi,

a customer of mine is getting the following error while trying to import a modified table into his sql database (4.02):

The following SQL error(s) occurred while accessing the Fattura table:

8111, “42000”,[Microsoft],[ODBC SQL Server Driver],[SQL server]Cannot dfine PRIMARY KEY constraint on nullable column in table ‘ADM Produzione$Fattura’
1750, “42000”,[Microsoft],[ODBC SQL Server Driver],[SQL server]Could not create constraint. See previous error

SQL:
ALTER TABLE “navision”.“dbo”.“ADM Produzione$Fattura” ADD CONSTRAINT “ADM Produzione$Fattura$0” PRIMARY KEY CLUSTERED (“Nr_Fattura”,“Nr_Riga_Fattura”,“Matricola”,“Anno_Fattura”)

What does that mean? (I’m not very smart about SQL Server) And how can it be solved?

Thank you

Hmmm … the problem seems to be, that when importing a modified table the existing CONSTRAINT is not dropped before creating the new (modified? was the PK changed?) one …

I guess you can not simply delete the existing table first as it contains some data?

You could try to drop the existing PK CONSTRAINT from SQL Server site, executing:

USE [navision}
GO
ALTER TABLE “dbo”.“ADM Produzione$Fattura” DROP CONSTRAINT “ADM Produzione$Fattura$0”

Then import the new FOB. Check if during the import the CONSTRAINT was created, if not you could add it manually:

USE [navision]
GO
ALTER TABLE “navision”.“dbo”.“ADM Produzione$Fattura” ADD CONSTRAINT “ADM Produzione$Fattura$0” PRIMARY KEY CLUSTERED (“Nr_Fattura”,“Nr_Riga_Fattura”,“Matricola”,“Anno_Fattura”)

Hope it’ll work!

Best regards,

Yes, a field was added.

Well, I might write a dataport, export all the data, delete the table, recreate it and inmport the data back… given my clumsiness where SQL is involved it might be easier! [:P]

I’ll try your suggestion and let you know, anyway. Thank you.

Hi there,

I’m the one of this “ADM Produzione”.

This script run without errors, but importing FOB is the same. I have 3 society on this db. As like I can’t delete a table because there are data on other society, have I to use script on each one?

Constraint is new to me (neither in Ben Gan sql bible I’ve seen before) but I see that when I drop constraint it drop index too. So I don’t try to drop on each table yet before a kindly backup [:$]

Thanks!

B.R.

Oscar

Hi Oscar!

The CONSTRAINT is actually the Primary Key/Clustered Index. As the new FOB changes the Primary Key of the table(s), the existing CONSTRAINT is invalid. Unfortunately, C/SIDE does not recognize and handle it itself, so I proposed to drop the CONSTRAINT manually, hoping it would be re-created on importing the FOB.

With NAV each C/SIDE table is created per company. As you say you have 3 companies, you have 3 “Fattura” tables:

“Company1$Fattura”, “Company3$Fattura”, “Company3$Fattura”; each table with its own “Primary Key Clustered”. Hence, you have to frop all three CONSTRAINTS, just change the “Company” part of the table name as marked bold (same goes for manual createion of the CONSTRAINT):

USE [navision}
GO
ALTER TABLE “dbo”.“ADM Produzione$Fattura” DROP CONSTRAINT “ADM Produzione$Fattura$0”
ALTER TABLE “dbo”.“Company2$Fattura” DROP CONSTRAINT “Company2$Fattura$0”
ALTER TABLE “dbo”.“Company3$Fattura” DROP CONSTRAINT “Company3$Fattura$0”

If this works, you don’t have to delete the whole table.

Hi Jorg,

I’ve dropped constraints but without PK fob could not replace table. It says I have no PK in table.

Now I try to insert the constraint again but SQL gives me back this:

Server: Msg 8111, Level 16, State 1, Line 1
Cannot define PRIMARY KEY constraint on nullable column in table ‘ADM Produzione$Fattura’.
Server: Msg 1750, Level 16, State 1, Line 1
Could not create constraint. See previous errors.

Regards, Oscar

Because I can’t run the table I try from Enterprise Manager. Deleted indexes of each company.

Then Design Table on each table, selecting the 4 field I set the PK. Now my index has a strange name but I can import and run the table in this way.

Before starting I have also another index called 1$ wich have the same fields selected…

I hope I can invoice on Monday [:S]

Regards and good W.E.

Oscar

So you’ve dropped the CONSTRAINTS successfully, but the FOB till can’t be imported. You should not at a PK, especially with a “strange name” with Enterprise Manager. This will cause a “gap” between C/SIDE and SQL Server, resulting in even more problems …

Please try to add the new CONSTRAINT manually, also for all three tables:

USE [navision]
GO
ALTER TABLE “dbo”.“ADM Produzione$Fattura” ADD CONSTRAINT “ADM Produzione$Fattura$0” PRIMARY KEY CLUSTERED (“Nr_Fattura”,“Nr_Riga_Fattura”,“Matricola”,“Anno_Fattura”)
ALTER TABLE “dbo”.“Company2$Fattura” ADD CONSTRAINT “Company2$Fattura$0” PRIMARY KEY CLUSTERED (“Nr_Fattura”,“Nr_Riga_Fattura”,“Matricola”,“Anno_Fattura”)
ALTER TABLE “dbo”.“Company3$Fattura” ADD CONSTRAINT “Company3$Fattura$0” PRIMARY KEY CLUSTERED (“Nr_Fattura”,“Nr_Riga_Fattura”,“Matricola”,“Anno_Fattura”)

Please regards that the fields should be as in the FOB. If this works, then please try to import the FOB again …

If this all does not work, then restore all original settings, and just implemement the new Key directly with C/SIDE in the live system.

BTW: This looks like a real bug in NAVSP2 …

… and this …

Server: Msg 8111, Level 16, State 1, Line 1
Cannot define PRIMARY KEY constraint on nullable column in table ‘ADM Produzione$Fattura’.
Server: Msg 1750, Level 16, State 1, Line 1
Could not create constraint. See previous errors.

… means, that one of the PK fields is allowed to NULL fields; you have to set it on NOT NULL (easiest via EM).

[:’(] Why didn’t I think of this?!?

Indeed, I have an other customer who had troubles with table relations - while importing fobs - It said that it could not drop the constraint on a key because it was referenced by an other table…

Thank you for your help, Jörg. The fob was finally imported! [:)]

Moved to SQL Forums