| |

VerySource

 Forgot password?
 Register
Search
Author: 121222

Database field type conversion problem

[Copy link]

0

Threads

29

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-11-27 16:45:01
| Show all posts
Do alter table operations in the query manager? Enterprise Manager--b GUI graphical tools are not as efficient as command lines. Although it is easy to operate
Reply

Use magic Report

0

Threads

34

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-11-27 20:30:01
| Show all posts
ALTER TABLE
Change the definition of the table by changing, adding, removing columns and constraints, or by enabling or disabling constraints and triggers.
ALTER COLUMN

Specifies to change the given column. If the compatibility level is 65 or less, ALTER COLUMN will not be allowed. For more information, see sp_dbcmptlevel.

The column to be changed cannot be:

Columns with data type text, image, ntext, or timestamp.

It is written in the online help, which means that the Alter Table method cannot change the text, image, ntext or timestamp column
Reply

Use magic Report

0

Threads

34

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-11-27 21:00:01
| Show all posts
It can be modified like this. This is an example. Change the ee field in table1 from ntext to text.
The reference is as follows:

BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
CREATE TABLE dbo.Tmp_Table1
(
ee text NULL
) ON [PRIMARY]
TEXTIMAGE_ON [PRIMARY]
GO
IF EXISTS(SELECT * FROM dbo.Table1)
EXEC('INSERT INTO dbo.Tmp_Table1 (ee)
SELECT ee FROM dbo.Table1 (HOLDLOCK TABLOCKX)')
GO
DROP TABLE dbo.Table1
GO
EXECUTE sp_rename N'dbo.Tmp_Table1', N'Table1','OBJECT'
GO
COMMIT
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list