Backup Database Tables with this Simple SQL Command

Database Table Backups on the Fly

This is a super simple SQL super power trick I learned from a mentor.

If you’re working in SQL Server Management Studio (SSMS) you can open up a New Query window and type in a simple “SELECT INTO” command to backup a database table on the fly.

Sample SQL SELECT INTO Statement

SELECT * INTO new_table FROM old_table_20221122

This is pretty simple. You’re making copying of a table like a “Save As” button would let you do.

This is also great for undoing something bad you’ve done by simply reversing the process.

SQL: How to Find Text in Stored Procedures

Searching for Text in a SQL Stored Procedure

I always write a blog article on things that took me a little to time to find when I working on various projects.

I’m working a project with another developer and they had sent me a screenshot of a SQL stored procedure that I needed to look at but they didn’t tell me the name of the file.

I needed to take some text from the screenshot and figure out which stored procedure it was in out of 100 or more.

Below is an example of the SQL script I used to find the text I was looking for. You’ll be searching the definition for you specific text.

SQL Script Example:
Find Text in Stored Procedures

SELECT DISTINCT
       o.name AS Object_Name,
       o.type_desc,
	   m.definition
FROM sys.sql_modules m
       INNER JOIN
       sys.objects o
         ON m.object_id = o.object_id
WHERE m.definition Like '%@RowString%';

I hope this help you solve your issue!

~Cyber Abyss