Solved

Script to create a SQL Server Table

Posted on 2014-02-05
4
448 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
Comment Utility
You could write a stored procedure for him and have him import and run it.
0
 
LVL 16

Expert Comment

by:Brian Pringle
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
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…
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 and will be exposed to the many uses the SELECT statement has.

763 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

9 Experts available now in Live!

Get 1:1 Help Now