SQLTeam.com | Weblogs | Forums

What is SQL scripting?


#1

Hi, I'm at beginner level of SQL, but heard lot about SQL scripting. Is it same as writing a queries or something else.


#2

Yes. SQL scripting involves writing SQL queries as well as organizing code as procedures, functions etc. There are various implementations of SQL from various vendors like Transact SQL (T-SQL) of SQLServer, PL SQL of Oracle etc
see this to understand on the basics of SQL

SQL basics


#3

An SQL Script contains one or more SQL/ PLSQL Statements. SQL Script is a command that is saved in SQL scripts. The SQL Scripting involves Procedures, Functions Views and Schema etc.. You can use SQL Scripts to create, edit, view, run and delete script files

We should be careful when we using the SQL Scripts…
• There should be no connection between the SQL Scripts and SQL commands.
• You can Cut and Paste the SQL Scripts from SQL Script Editor to use as SQL Commands.
• Bind Variables are not supported by SQL Scripts.


#4

Yes, those are "SQL scripting". But often "SQL scripting" refers to an automated process of generating SQL. There are option in SSMS to do that, or you can write T-SQL that generates other T-SQL.

As a very simple example, if you wanted a script to list the first 10 rows of every table, you could do this:

SELECT 'SELECT TOP (10) * FROM [' + SCHEMA_NAME(schema_id) + '].[' + name + ']; '
FROM sys.tables
ORDER BY 1

That's easier, and more flexible, than writing the actual SELECT statements for every table yourself.