Solved

Script to create a SQL Server Table

Posted on 2014-02-05
4
453 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Slow Connectivity over ODBC 8 32
Linked Server Issue with SQL2012 3 22
T-SQL: Do I need CLUSTERED here? 13 38
SQL - Use results of SELECT DISTINCT in a JOIN 4 13
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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
Viewers will learn how the fundamental information of how to create a table.

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now