How to create multiple stored procedures from .sql files - sql

I have about 100 stored procedures files that I want to add to a new database that I created. Is there any way I can just drop them in a folder to import them? When I tried that, like how you would with windows explorer, it just opened them all in query windows.
I am using SQL Server Management Studio.

Right now you did not respond to the question in the comments to make your question clearer, but I have these two suggestions
Assuming you already have a database that uses these procedures:
Right click the database in Management Studio and click on Task
Click on Generate Scripts
In the dialog that comes up, click next as you specify the right options
Select the checkbox for "Stored Procedures"
Select All the required stored procedures
Select option to generate script to a new window or file
You are done. Run you script on the other database
If you have access to Visual Studio
Create a new SQL Server Database project
Select the connection string of your new database
Create a stored procedure folder and add all the stored procedure files from your system to it
Right click the project and click Deploy/Publish
Hope you have the tables referenced in the stored procedures

Related

How do I script out a full database to a series of creation scripts?

I'm looking for a way to script out an entire SQL Server 2015 database to write table creation scripts, stored procedure scripts, triggers, etc etc to a folder so I can set a baseline for a TFS repository solution. Apart from manually exporting each script one by one, is there a way to do a bulk export?
Obviously I'm not talking about data here, I'm talking strictly about exporting creation SQL file scripts to a folder for a single database.
Please try with SQL Server Management Studio.
To open the Generate and Publish Scripts Wizard. In Object Explorer, expand Databases, right-click a database, point to Tasks, and then click Generate Scripts. Follow the steps in the wizard to script the database objects. On the Choose Objects page, select the objects to be included in the script.
https://technet.microsoft.com/en-us/library/ms178078(v=sql.105).aspx
you can generate sql scripts in ssms by following steps:
Right Click on the Database
Go to task and then Click on "Generate Scripts..."
follow the wizard steps to create scripts

Editing Stored Procedures in MSSQL Server 2008

I imported a database for MSSQL 2008 for development. I know they have stored procedures because I was able to edit them live with the web interface front that they have.
Now that I have the database loaded in a development location how do I access them? Are they normally stored in a table? I see at least one table with stored procedures. Is there a way to edit them with a built in text editor?
EDIT: I do have SQL Management Studio installed, just not sure how exactly to access/edit the procedures.
Normally you would use SSMS - SQL Server Management Studio to do this. Its usually included with SQL Server, so you may just need to install it.
http://msdn.microsoft.com/en-us/library/ms174173.aspx
or download it here:
http://www.microsoft.com/en-us/download/details.aspx?id=7593
Got it!
So different from working with MySQL.
In Object Explorer, connect to an instance of Database Engine and
then expand that instance.
Expand Databases, expand the database in which the stored procedure
belongs, and then expand Programmability.
Expand Stored Procedures, right-click the procedure to modify, and
then click Modify.
Modify the text of the stored procedure.
To test the syntax, on the Query menu, click Parse.
To modify the stored procedure, on the Query menu, click Execute.
To save the script, on the File menu, click Save As. Accept the file
name or replace it with a new name, and then click Save.
try like this:
If You Installed SQL SERVER Management Studio then Type ssms in RUN
Select Installed SQL SERVER Instance and Log in
Then Type Below command, it gives you Text of stored procedure
sp_helptext 'Procedure_name'

Cannot create new SQL data tables in Visual Studio Express 2012

I have created a new SQL database in my Visual Studio Express 2012 website. This appears in the AppData folder. I can open the database in the Database explorer and now I want to add some empty data tables.
I right click on the Tables folder and select Add New Table. I get the screen (below). When I have finished I click Update and it appears to do something but then the table has not appeared in the Tables folder.
I have also tried clicking the save button, and saving the table manually in the AppData folder, but yet it still does not appear in the Tables folder.
What am I doing wrong please?
Here is the solution-
https://www.youtube.com/watch?v=HwA-tNvU3hw
Steps 1-Change the name of table [dbo].[table---(change this)]
Step 2-Don't save the table after creating them rather choose option update table and then update database.
Step 3-On refreshing the tables you will be able to see your table.
In my case, Visual Studio was saving the table to my documents. It should be writing the table to the MDF file. I used the designer to generate the T-SQL, then I copied the T-SQL right clicked on the tables folder, chose 'New Query' pasted the T-SQL commands, set the target database as shown in the image and ran the query. Finally!
In the 'New Query' window within VS 2012 Express, there is an 'available databases' drop down. Choose your database that is part of your solution and execute the T-SQL
Have you tried refreshing the tables list on the right hand side?
Make following change:
CREATE TABLE [dbo][change_this_name]
click the update button on top left corner.
I was up against this same problem in Visual Studio 2013 Community. The solution was to go to Tools -> Extensions and Updates and then download the SQL server compact / sql lite toolbox. VS2013 will prompt you to restart for the new extension to take effect.
After the restart, your databases will have a red "x" on them. Right click them, select modify connection and then take the defaults.
Visual Studio will then pull its head out of its hind parts, and those tables you've been saving that never appeared in the tables folder before will be auto-magically there.
Hope this helps.

How to Export Whole Database with Data Inside

I can Generate Create Scripts of my database in MS Sql Server Management Studio. But I need to move the database to a shared server with all the data in it.
Since I don't have full admin rights, I can not backup/restore .bak files or attach there. Is there any way to generate "Insert" queries which insert all of the data when I run them after create queries.
Yes. Here's how to do it:
Open up SSMS
Right-click on your database
Tasks -> Generate Scripts...
Choose the objects you want to script out (it sounds like you want the whole DB)
Under Set Scripting Options click the Advanced button
For the item Types of data to script, select Schema and data

Create db from db project

Does anyone know how to create an entire database from a visual studio database project? Rather then running logs of smaller scripts individually.
Thanks
In VS express you do the following- It should be similar in the other versions but I don't have them in front of me.
Open Database Explorer (Ctrl-Alt-S)
Right Click "Data Connections" > "Add Connection"
Set 'Data Source' To Microsoft SQL Server Database File
Enter a name for your new Database
Choose your authentication method
It should confirm the creation of the database from there...
In Database Explorer Expand your Database and right click tables > Add new table and so on
It looks like I completely misunderstood the question. If you are trying to generate a script from an existing project for export the Database publishing wizard may do what you need.
http://www.microsoft.com/downloads/details.aspx?FamilyID=56E5B1C5-BF17-42E0-A410-371A838E570A&displaylang=en
Are you using vs2008 team edition? If so use the db edition and you can use schema compare to create tables, along with stored procedures, views, etc.
http://www.microsoft.com/downloads/details.aspx?FamilyID=bb3ad767-5f69-4db9-b1c9-8f55759846ed&displaylang=en
The other way I have done is to publish the database, which will create a large sql file for schema and/or data, and then you can execute that in SQL Server Management Suite.