Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 to create a batch file for .sql files

Author  Topic 

arthiasha
Starting Member

40 Posts

Posted - 2012-10-09 : 01:51:46
Hi,

I need to create a batch file with the scripts which is in .sql format.
table_schema.sql
stored procedures.sql
uddtypes.sql
uddtables.sql
grant permission.sql
sql injection.sql
users.sql

These files hold all scripts for creation of schema, stored procedures, users, uddt's etc
I need to create a single batch file so that when i run it, automatically the schema with stored procedures and everything should be created in my mssql 2008.

create table..... (execute 'table_schema')
create table.....(execute 'stored procedures')
....
...

it should be given like this
can u give me the script?

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-10-09 : 07:05:45
In SQL Server Management Studio, in object explorer, right-click on the database name and select Tasks -> Generate Scripts and follow through the wizard.

If you are trying to port a database from one server to another, there are other ways as well - backup and restore, SSIS etc.
Go to Top of Page

arthiasha
Starting Member

40 Posts

Posted - 2012-10-09 : 07:46:58
Thanks for your relpy, but i dont want to do this way because i need to use this as a deploy script to create a new database with its schema etc..as well as bcp it.

I wanted a script like
create database [dbname]
...
(call all the .sql scripts-table schema,procedures etc
....
....

so that it creates the whole database with its schema procedure uudtypes etc.
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-10-09 : 07:55:28
I am afraid I did not follow the requirement.

If you are trying to create a database with all the schema objects and none of the data, what I described above would work. You will generate the scripts once (which is a manual process), and then use that script to create your deployment package/script.

You also mentioned BCP. If you are trying to deploy the database with the data, backup and restore may be a better option. That also can be scripted.
Go to Top of Page
   

- Advertisement -