我以为这是小事,但事实并非如此……我相信有一个简单的方法可以做到,但我找不到。真可耻。
我想导入/导出数据库本身、表、约束(外键等)。我宁愿不拿数据,但如果没有其他办法,我可以把它处理掉。
所以…如何使用MS SQL Server Management Studio导出数据库?如何导入?
我找到的唯一解决方案是右键单击表并“script to Create”,但我有大约100个表,所以我宁愿避免这种情况。
谢谢!
我以为这是小事,但事实并非如此……我相信有一个简单的方法可以做到,但我找不到。真可耻。
我想导入/导出数据库本身、表、约束(外键等)。我宁愿不拿数据,但如果没有其他办法,我可以把它处理掉。
所以…如何使用MS SQL Server Management Studio导出数据库?如何导入?
我找到的唯一解决方案是右键单击表并“script to Create”,但我有大约100个表,所以我宁愿避免这种情况。
谢谢!
右键单击数据库本身,任务->生成脚本…
然后按照向导操作。
对于SSMS2008+,如果您还想导出数据,在“设置脚本选项”步骤中,选择“高级”按钮,并将“脚本数据类型”从“仅模式”更改为“仅数据”或“模式和数据”。
另一种解决方案是-备份和恢复数据库
备份系统数据库
使用Microsoft SQL Server Management Studio Express备份系统数据库,请执行以下步骤:
Download and install Microsoft SQL Server 2008 Management Studio Express from the Microsoft web site: http://www.microsoft.com/en-us/download/details.aspx?id=7593 After Microsoft SQL Server Management Studio Express has been installed, launch the application to connect to the system database. The "Connect to Server" dialog box displays. In the "Server name:" field, enter the name of the Webtrends server on which the system database is installed. In the "Authentication:" field select "Windows Authentication" if logged into the Windows machine using the Webtrends service account or an account with rights to make changes to the system database. Otherwise, select "SQL Server Authentication" from the drop-down menu and enter the credentials for a SQL Server account which has the needed rights. Click "Connect" to connect to the database. Expand "Databases", right-click on "wt_sched" and select "Tasks" > "Back Up..." from the context menu. The "Back Up Database" dialog box displays. Under the "Source" section, ensure the "wt_sched" is selected for the "Database:" and "Backup type:" is "Full." Under "Backup set" provide a name, description and expiration date as needed and then select "Add..." under the "Destination" section and designate the file name and path where the backup will be saved. It may be necessary to select the "Overwrite all existing backup sets" option in the Options section if a backup already exists and is to be overwritten. Select "OK" to complete the backup process. Repeat the above steps for the "wtMaster" part of the database.
恢复系统数据库
使用Microsoft SQL Server Management Studio恢复系统数据库,请执行以下步骤:
If you haven't already, download and install Microsoft SQL Server 2008 Management Studio Express from the Microsoft web site: http://www.microsoft.com/en-us/download/details.aspx?id=7593 After Microsoft SQL Server Management Studio has been installed, launch the application to connect to the system database. The "Connect to Server" dialog box displays. In the "Server type:" field, select "Database Engine" (default). In the "Server name:" field, select "\WTSYSTEMDB" where is the name of the Webtrends server where the database is located. WTSYSTEMDB is the name of the database instance in a default installation. In the "Authentication:" field select "Windows Authentication" if logged into the Windows machine using the Webtrends service account or an account with rights to make changes to the system database. Otherwise, select "SQL Server Authentication" from the drop-down menu and enter the credentials for a SQL Server account which has the needed rights. Click "Connect" to connect to the database. Expand "Databases", right-click on "wt_sched" and select "Delete" from the context menu. Make sure "Delete backup and restore history information for databases" check-box is checked. Select "OK" to complete the deletion process. Repeat the above steps for the "wtMaster" part of the database. Right click on "Databases" and select "Restore Database..." from the context menu. In the "To database:" field type in "wt_sched". Select the "From device:" radio button. Click on the ellipse (...) to the right of the "From device:" text field. Click the "Add" button. Navigate to and select the backup file for "wt_sched". Select "OK" on the "Locate Backup File" form. Select "OK" on the "Specify Backup" form. Check the check-box in the restore column next to "wt_sched-Full Database Backup". Select "OK" on the "Restore Database" form. Repeat step 6 for the "wtMaster" part of the database.
礼貌- http://kb.webtrends.com/articles/How_To/Backing-Up-and-Restoring-the-System-Database-using-MS-SQL-Management-Studio
for Microsoft SQL Server Management Studio 2012,2008.. 首先复制数据库文件.mdf和日志文件.ldf,并粘贴到sql server安装文件“Programs Files->Microsoft sql server ->MSSQL10.SQLEXPRESS->MSSQL->DATA”。 打开Microsoft Sql Server。 右键单击数据库->选择附加…选项。
我尝试了上面的答案,但生成的脚本文件非常大,我在导入数据时遇到了问题。我最终分离了数据库,然后复制.mdf到我的新机器,然后将它附加到我的新版本的SQL Server Management Studio。
我在微软网站上找到了如何做到这一点的说明: https://msdn.microsoft.com/en-us/library/ms187858.aspx
注意:卸载数据库后,我在这个目录中找到了。mdf文件: C:\Program Files\Microsoft SQL Server\
我想与你分享我的解决方案导出数据库与微软SQL Server管理工作室。
导出数据库
打开一个新请求 复制粘贴此脚本
DECLARE @BackupFile NVARCHAR(255);
SET @BackupFile = 'c:\database-backup_2020.07.22.bak';
PRINT @BackupFile;
BACKUP DATABASE [%databaseName%] TO DISK = @BackupFile;
不要忘记将%databaseName%替换为要导出的数据库的名称。
注意,此方法提供的文件比菜单中的文件要轻。
从SQL Server Management Studio导入此文件。 不要忘记事先删除数据库。
单击恢复数据库
添加备份文件 验证
享受吧!:):)
导出和导入数据库与MS SQL Server管理工作室
1.从SQL Server导出数据库
在对象资源管理器上右键单击要导出的数据库 在数据库节点中列出。 选择任务,然后选择导出数据层应用程序 单击“导出设置” 确保选中“保存到本地磁盘” 浏览路径,保存为。bacpac文件 单击“下一步”和“下一步”导出
2.导入数据库到SQL Server
在对象资源管理器右侧的数据库节点上。 选择导入数据层应用程序 单击导入设置 确保选中“从本地磁盘导入” 浏览该路径并打开.bacpac文件 单击“下一步”和“下一步”导入
使用服务器管理工作室(SSMS)导入和导出向导是简单的。你可以把整个DB直接转储到另一个数据库中,不需要把它存储到临时文件中。
>在SQL Server Management Studio中,连接到SQL Server数据库引擎实例。
>展开数据库。
>右键单击数据库。
>指向任务。
>单击以下选项之一。
导入数据 出口数据
参考:MS文档导入和导出向导