Click here to Skip to main content
15,896,539 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai,

I have a Script for 40 tables which is in one folder. I want to create table to my database using this script file. Please anybody help, how to create tables using this script at a time.

Thank you
Posted
Updated 2-May-12 19:23pm
v2

Run the script one-by-one?!

Ok, to run them at once, here: Using SQLCMD to Execute Multiple SQL Server Scripts[^]
 
Share this answer
 
For this you will have to create a batch file which will read your scripts from the files present in some folder and then execute it. Please refer following links:

http://social.msdn.microsoft.com/Forums/en/sqlgetstarted/thread/7e00c796-5854-4a2c-91d3-7b325420fd14[^]

http://stackoverflow.com/questions/3794897/need-help-to-write-bat-file-that-execute-sql-scripts-in-sql-server-2008-and-ano[^]

Generating osql Batch Scripts[^]

Regards
Praveen
 
Share this answer
 
Manually with SQL ManagementStudio
Open or create new database
open scriptfile (*.sql) in query window
execute...

for C# code, example is:
C#
//create DB
                string sqlString = string.Format("USE [master] CREATE DATABASE {0}", dbName);
                SqlConnection conn = new SqlConnection(ConnectionString);
                SqlCommand cmd = new SqlCommand(sqlString, conn);
                bool err = false;
                try
                {
                    conn.Open();
                    int r = cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    created = "\nCreate database failed: " + ex.Message;
                    err = true;
                }
                conn.Close();
                if (err) return created;



see codeproject link:
Deploy SQL Server databases easily with an Installer class[^]

excerpt from link:
C#
//delete all GO cmds
                    sr = new StreamReader("CreateTables.sql");
                    readsql = sr.ReadToEnd();
                    
                    Regex regex = new Regex("^GO", RegexOptions.IgnoreCase | RegexOptions.Multiline);
                    string[] SqlLine = regex.Split(readsql);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900