Solved

Script to create a SQL Server Table

Posted on 2014-02-05
4
459 Views
Last Modified: 2014-02-05
I have a windows form .net application that uses SQL Server 2012 Express.  I have a user of this application who knows nothing of SQL Server and he needs a new table added to the SQL Server Database that my application uses.  Is there a way to create an executable script that I can send to this user that would execute a SQL script to create a new table?  I do have SQL Server management studio so is there anything in this tool that will allow me to create an executable script for this user?  I only want this user to execute the script and let the script to the work of create a new table in an existing database.
0
Comment
Question by:hojohappy
  • 3
4 Comments
 
LVL 16

Expert Comment

by:Brian Pringle
ID: 39836927
You could write a stored procedure for him and have him import and run it.
0
 
LVL 16

Expert Comment

by:Brian Pringle
ID: 39836933
This article describes how to import the stored procedure.

http://msdn.microsoft.com/en-us/library/vstudio/bb896231(v=vs.100).aspx
0
 
LVL 16

Expert Comment

by:Brian Pringle
ID: 39836940
The other option would be to make a C# program to connect to the database server and then issue the commands.  You would want to prompt the user for the name or IP address of the server, the username and password of a user account that has administrative rights on the DBMS.  You could then publish the app and send the executable or installer to him.
0
 
LVL 16

Accepted Solution

by:
Surendra Nath earned 500 total points
ID: 39836960
are you looking for something like a batch file or a exe which upon execution at your client site will automatically create the table for you in the database??

If the answer to the above question is yes
then follow the below steps

1) write the create table statement for your table or just right click on the existing table in the SSMS and say create script.

2) Save this script in a file, let us say test.SQL

3) Now create a batch file let us say testBatch.bat

4) within this batch file you can use SQLCMD to connect to the user database and execute test.sql
such as below
sqlcmd -S myServer\instanceName -i C:\test.sql

Now send you client both test.sql and testBatch.bat and ask him to double click on testBatch.bat and that will do the rest.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question