简体   繁体   English

SQL SERVER恢复数据库添加了新列/ PK?

[英]SQL SERVER Restore Database with New Columns/PK added?

Im adding a new column with primary keys to a database, but there is data within it. 我将一个带有主键的新列添加到数据库中,但其中有数据。 However they want to backup the data and then restore it to the new database with the new column/primary key. 但是,他们希望备份数据,然后使用新的列/主键将其还原到新数据库。 When restoring a database is there an option you can select to make sure it doesn't get rid of the new column, and just inserts the database with the new column there (this new column also has a default value as well). 恢复数据库时,您可以选择确保它不会删除新列,只需在其中插入带有新列的数据库(此新列也具有默认值)。

Thanks 谢谢

The backup and restore process will take an exact snapshot of your data and restore it identically. 备份和还原过程将获取数据的精确快照并以相同方式还原。 If you want to "merge" two databases then you will need to script both the added columns, tables and data to the production database. 如果要“合并”两个数据库,则需要将添加的列,表和数据编写到生产数据库中。 There are tools in SQL management studio for this. SQL管理工作室中有这样的工具。

re comments 重新评论

Dropping an index of key will not affect the underlying data. 删除密钥索引不会影响基础数据。 It may block you accessing it while the key is being created (the clustered index is the order the data is stored in the data file). 它可能会阻止您在创建密钥时访问它(聚集索引是数据存储在数据文件中的顺序)。 If you want to transfer data between dev and prduction it may be quicker to resore a copy of dev as a spare database on the prod seerver and script an insert between the two databases. 如果要在dev和prduction之间传输数据,可以更快地将dev的副本作为备用数据库重新生成,并在两个数据库之间编写插入脚本。 Note SQL takes restore seriously and uses all resources to do it as quickly as possible (to the detriment of all other SQL processes) so truncate every table you dont need to transfer data from before backup 注意SQL需要认真恢复,并尽可能快地使用所有资源(不利于所有其他SQL进程),因此截断在备份之前不需要传输数据的每个表

The primary key is the index which determins the idenity of each unique row. 主键是确定每个唯一行的标识的索引。 The custered index determins the order the data is stored and accessed in the file. 聚合索引确定数据在文件中存储和访问的顺序。 If you have two rows with the same primary key (which may not be unique) then SQL will add a uniquifying column in the background. 如果您有两行具有相同的主键(可能不是唯一的),那么SQL将在后台添加一个无统一的列。 SQL will lock the table whist a new clustered index is being implimneted. SQL将锁定表,而新的聚簇索引正在受到限制。 the underlying data istself will not be changed. 基础数据本身不会改变。

You can restore last backup to a new temp Database then use Import menu in management studio to copy your old data to new database. 您可以将上次备份还原到新的临时数据库,然后使用管理工作室中的“导入”菜单将旧数据复制到新数据库。

Check this link for more about import data. 有关导入数据的更多信息,请查看此链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM