如何从SQL脚本创建数据库。 [英] How to create database from SQL script.

查看:301
本文介绍了如何从SQL脚本创建数据库。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,

在MS SQL Server 2008中从数据库创建脚本后,如果我们想在其他PC上运行所有数据库,那么我们可以在SQL server中使用SQL脚本来创建数据库。

以相反的顺序从给定的脚本创建数据库。

如何从MS SQL Server 2008中的SQL脚本创建SQL数据库。



请给出步骤或链接。

Dear Sir,
After creating script from database in MS SQL server 2008,if we want to run all the database in other PC,then we can crate Database using SQL script in SQL server.
In reverse order to create database from given script.
How to create the SQL Database from SQL script in MS SQL server 2008.

Please give steps or links.

推荐答案

CREATE DATABASE [test]
 CONTAINMENT = NONE
 ON  PRIMARY
( NAME = N'test', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\test.mdf' , SIZE = 5120KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON
( NAME = N'test_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\test_log.ldf' , SIZE = 2048KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO







或只是






or simply just

CREATE DATABASE [test]


基本上,如果您在一台服务器上编写了整个数据库的脚本,那么您可以使用该脚本并在另一台服务器上运行它,例如在master数据库中运行。



完整脚本应包含数据库创建(CREATE DATABASE ...),之后所有必要的对象创建进入该数据库。



要运行脚本,您可以使用例如SSMS(Sql Server Management Studio)
Well basically if you have scripted the whole database on one server, you can take that script and run it on another server for example in master database.

The full script should contain the database creation (CREATE DATABASE...) and after that all necessary object creations into that database.

To run the script, you can use for example SSMS (Sql Server Management Studio)


如果你想要从数据库生成所有表的脚本,那么你必须这样做。


1.转到对象资源管理器。选择要生成脚本的数据库。右键单击它。



您可以看到任务。点击任务..在那里你可以看到生成脚本还原。点击那个。它将带你到巫师。在向导中,您可以选择要生成的表。默认情况下,它将为所有表和该数据库生成脚本。选择一个路径并单击下一步直到完成启用。然后点击完成。转到并在向导中提到的路径中检查脚本。它将为数据库以及所有表创建脚本。
If you want to generate script for all tables from a database, then you have to do as below.

1. Go to Object explorer. Select the database which you want to generate script. Right click it.

You can see Tasks. click on tasks.. There you can see Generate scripts below restore. click that. it will take you to wizard. In the wizard you can select the tables which you want to generate. By default it will generate script for all tables and that database. Select a path and click on next until finish enables. Then click on finish. Go and check the script in the path you mentioned in the wizard. It will have create script for database and as well for all tables.


这篇关于如何从SQL脚本创建数据库。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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