?
Solved

Script to create a SQL Server Table

Posted on 2014-02-05
4
Medium Priority
?
469 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

752 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