Search code examples
sqlsql-serversql-server-2014

How can I back up a stored procedure in SQL Server?


Last time when I was working with my SQL Server 2014 and suddenly due to a power failure my database goes corrupted and next time after running DBCC CHECKDB I found some of stored procedures that I have created on my SQL Server are still missing. So there is any method from which I can create a successful backup for my stored procedure?


Solution

  • One Possibilty is: In SQL Server Manangement Studio rightlick on your Database - Tasks - Generate Scripts... Here you can specify which object you want to script and where to save the script file.

    What's my favourite solution (though it's more work) is to have all my databases in Database Projects in Visual Studio. (Keyword: SQL Server Data Tools). Don't know if that is interesting for you but it's very powerful and a great thing to deploy databases, manage source code (TFS for example)...all the visual studio benefits.