如何在sql server 2008中将数据类型位更改为int [英] how to change datatype bit to int in sql server 2008

查看:144
本文介绍了如何在sql server 2008中将数据类型位更改为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在sql server 2008中将数据类型位更改为int

解决方案

在sql server中有一种名为"tiny int"的数据类型,它等效于位或字节.您可以在TSQL中使用Cast或Convert函数将值转换为int或small int等.

请参考下面的链接

http://msdn.microsoft.com/en-us /library/ms187928.aspx


如果您要更改表本身,则从字节到Int的转换不会有任何问题,因为您将向相同的值添加更多字节..仅从int到bit会出现问题(值将被截断).

您可以使用以下命令轻松地执行此操作.

  ALTER   TABLE  dbo.YourTable  ALTER   YourColumnName  INT  


尝试:
 ALTER   TABLE  table_name  ALTER   column_name  INT  



另一种选择是创建类型为INT的新列,并使用现有的BIT列填充此字段&完成后,删除旧列.

如果您想在实际删除原始列之前先查看数据,这将是安全的.


how to change datatype bit to int in sql server 2008

解决方案

There is a data type called ''tiny int'' in sql server which is equivalent to bit or byte.. You could use Cast or Convert function in TSQL to convert the value to int or small int etc

Please refer the link below

http://msdn.microsoft.com/en-us/library/ms187928.aspx


If you want to Alter the table itself converting from byte to Int will not have any problems as you are adding more bytes to the same value.. Only from int to bit will be a problem (values will be truncated)..


You can easily do this using the following command.

ALTER TABLE dbo.YourTable ALTER COLUMN YourColumnName INT


Try:
ALTER TABLE table_name ALTER COLUMN column_name INT



Other option is to create new column of type INT, populate this field with existing BIT column & drop old column once you are done.

This will be safe in case you want to see the data before you actually drop the original column..


这篇关于如何在sql server 2008中将数据类型位更改为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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