更改列的数据类型 [英] change the datatype of a coumn

查看:133
本文介绍了更改列的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQLSERVER 2005中有一个表,里面已经有一些数据.

我想更改列的数据类型.
当我尝试更改列的类型时,它说的是诸如您无法更改此列,因为您已经在此表中拥有数据,因此您需要删除并重新创建表"之类的消息.

更改表中列的数据类型(即使其中包含一些数据)的任何解决方案?

我尝试对单个表进行备份,以便删除并创建新表,然后将备份表中的数据发布到其中,但是我没有找到对单个表进行备份的选项.

I have a table with some data already in it in SQLSERVER 2005.

I want to change the data type of a column.
When I tried to change the type of the column it is saying a message like "You can''t change this because you already have data in this table so you need to drop and recreate the table".

Any solution for this to change the data type of the column in a table even it has some data in it?

I tried to take the backup of the single table, so that I will drop and create the new table and then post this backup table data in it but I didn''t find an option to take the backup of single table.

Is there any way to take a backup of single table?

推荐答案

您可以创建一个新表并将数据复制到其中(甚至已经转换了列数据).然后,您可以清除它并更改列,然后将其复制回去.大多数时候,您还可以删除表并重命名新表.

顺便说一句,您是使用SQL执行此操作还是使用服务器管理器菜单?

您可以直接尝试SQL并查看其是否有效,例如:

You create a new table and copy the data into it (even convert the column data already). Then you can clear it and change the column and copy it back. Most of the time you could also just drop the table and rename the new table.

By the way, are you using SQL to perform this or using the server manager menu''s?

You could try SQL directly and see if this works, like:

ALTER TABLE [dbo].[person]
ALTER COLUMN [lastname] VARCHAR(35) NULL
GO



如果这是主键的一部分,则无法使用.

祝你好运!



Won''t work though if this is (part of) the primary key.

Good luck!


这篇关于更改列的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆