如何将表记录重置为默认值 [英] How I can reset my table records to default

查看:78
本文介绍了如何将表记录重置为默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,亲爱的朋友

当我将ID列(浮点)数据类型更改为(nvarchar)时,我正在使用SQL Server 2008我丢失了正确的5000条记录,现在只有一个ID还有更多超过2或3个可用记录,所以在更改数据类型后删除主键并保存按钮会出现一条消息

(你的表格数据会丢失)

请帮帮我我可以重置我的记录



非常感谢朋友



我尝试了什么:



我尝试过最后一次备份,但只有2000条记录,但没有专业人员可以备份

Hello, dear friends
I am using SQL Server 2008 when I changed ID column (float) data type to (nvarchar) I lost the correct 5000 records, now on just one ID there is more than 2 or three records available, so after change data type and remove primary key with save button a message appeared
(Your table data will be lost)
Please help me how I can reset my records

Thanks so much friends

What I have tried:

I tried last backup but just 2000 records were there but no one a professional there to take a backup

推荐答案

0)使用浮点作为ID列不是最好的主意。如果你认为你的id会很多,请使用bigint。



1)添加数据后,更改列的类型将导致所有的丢失表中的数据。



2)如果是我,我会用相同的模式创建一个全新的表,更改所需列的类型,然后插入从旧表到新表的记录,记住要将相应的列数据转换为新模式的类型。

0) Using a float for an ID column is not the best idea. If you think your ids are going to be numerous, use a bigint.

1) After adding data, changing the type of a column will result in the loss of all data in the table.

2) If it were me, I would create a whole new table with the same schema, change the type of the desired columns, and insert records from the old table into the new one, remembering to cast.convert the appropriate columns data into the new schema's type.
-- duplicate a table's schema

SELECT TOP 0 * INTO NewTable FROM OldTable;

-- after you do that, use the table designer to alter the necessary columns' type

-- and then do a query something like this

INSERT INTO NewTable
SELECT col1,
       Convert(newtype, col2) AS col2,
       ...
FROM OldTable;





编辑=============================



雅知道当有人在没有提供理由的情况下给出答案时,它让我感到震惊。请记住,问题的质量直接影响答案的质量。



EDIT =============================

Ya know, it thrills me to no end when someone 1–votes an answer without providing a reason why. Remember, the quality of the question directly affects the quality of the answer.


您刚刚学到了专业管理员为了完成无用的备份而浪费时间的原因。这是因为有一天,无用的备份变得有用而且非常宝贵,但是人们永远都不知道它何时会发生。

You have just learned the hard way the reason why professional admins are loosing their time doing/organizing useless backups. It is because one day, the useless backup become useful and invaluable, but one never know when it will happen.
引用:

我将ID列(浮点)数据类型更改为(nvarchar)我丢失了正确的5000条记录

I changed ID column (float) data type to (nvarchar) I lost the correct 5000 records



我也猜想现在,你明白为什么试验实时数据的原因是一个坏主意。



您的解决方案:采取措施防止出现这种情况。对于你的实际问题,为时已晚。

- 备份,备份备份

- 从不试验实时数据,总是制作副本,当出现问题时,它只是副本。


I also guess that now, you understand the reason why experimenting on live data is a bad idea.

Your solution: Take actions to prevent ever being in this situation. For your actual problem, it is too late.
- Backups, backups backups
- never experiment on live data, always make copies, when something go wrong, it is only a copy.


这篇关于如何将表记录重置为默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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