Solved

Script to create a SQL Server Table

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

862 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

28 Experts available now in Live!

Get 1:1 Help Now