change data type ntext to text, SQL Server

Asked

Viewed 506 times

0

I need to change the data type of a field that is in "ntext" to "text". The reason is that I’m having trouble pulling this value from the database and generating a PDF with the php DOMPDF component.

When trying to change command line:

ALTER TABLE MyTable ALTER COLUMN mycolumn text

get the following error:

[Err] 42000 - [SQL Server]Cannot change mycolumn column for text data type

Is there any other way to change the data type of a table? Or force?

  • What kind of problem occurs? // You have tried retrieving column content using conversion to nvarchar(max) and only after passing to the DOMPDF class? // Have you tested whether the same problem does not occur when the data type is text?

  • With the type "text" I have no problems, also I did not think about converting the nvarchar(max).

1 answer

1


Try this:

ALTER TABLE mytable ADD mycolumn2 TEXT

UPDATE mytable SET mycolumn2 = mycolumn

ALTER TABLE mytable DROP column mycolumn 

ALTER TABLE mytable ADD mycolumn TEXT

UPDATE mytable SET mycolumn = mycolumn2

ALTER TABLE mytable DROP COLUMN mycolumn2
  • 1

    That wasn’t my ideal, but I did something similar, Valew.

  • The times ideal and necessary are different things rsrs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.