SQL Scripts are lists of SQL sentences written in a single file, meant to be executed sequentially. Depending on the particular RDBMS system, SQL scripts can have procedural language characteristics, such as control-of-flow constructs.
Questions tagged [sql-scripts]
437 questions
1
vote
1 answer
Insert and initialize a SQL column with value dependent on another column data
I am completely new to writing SQL scripts and could use a little help. I need to create a script that will run only once and add a column to an existing table. This column needs to have a value directly dependent to another column's value. The…

Eddie D
- 349
- 1
- 5
- 16
1
vote
0 answers
How to save SqlCmd commands into a file?
I am using SqlCmd for SQL Server 2008. I want to save all the commands that I have typed in SqlCmd into a text file or script file. Is it possible? If so how to do so?

aspiring
- 1,557
- 2
- 20
- 43
1
vote
3 answers
How to Corrupt your database to check your sql integirty check logic is working?
I have written scripts for database maintains plan
now i want to test my script
i dont have any currpted database then how can i belive my integirty check script giving right error message if my DB is corrpted
i want to corrpt my database to test…

Yogesh
- 150
- 1
- 4
- 20
1
vote
2 answers
Does [My]SQL have a Pre-Processor-like Facility?
I'm writing a small deployment SQL script for my first database-driven app.
In the process, I find that I repeat myself a lot, for instance:
GRANT USAGE ON *.* TO 'foo'@'localhost';
DROP USER 'foo'@'localhost';
CREATE USER 'foo'@'localhost'…
Vulcanus
1
vote
1 answer
Scripting all data from database causing tons of Foreign Key Constraint conflicts when re-running
I am using an EF code first generated database which provides some seed data, and imported data from other databases (ten thousands of rows, so it doesn't make sense to seed in EF). In an effort to streamline the process I figured I could just…

SventoryMang
- 10,275
- 15
- 70
- 113
1
vote
1 answer
EF Migrations Update-Database: Specify Script Name
Before applying a migration in EF Code First, you can ask to see the SQL script it intends to apply with:
PM> update-database -script
Unfortunately this opens a script named something like tmp939D.sql in Visual Studio and then freezes the IDE until…

Chris Moschini
- 36,764
- 19
- 160
- 190
1
vote
2 answers
Write SQL script to insert data
In a database that contains many tables, I need to write a SQL script to insert data if it is not exist.
Table currency
| id | Code | lastupdate | rate |
+--------+---------+------------+-----------+
| 1 | USD | 05-11-2012 | 2 …
user597987
1
vote
6 answers
Execute Stored Procedure for List of Parameters in SQL
I have an Stored Procedure that have an argument named Id:
CREATE PROCEDURE [TargetSp](
@Id [bigint]
)
AS
BEGIN
Update [ATable]
SET [AColumn] =
(
Select [ACalculatedValue] From [AnotherTable]
)
Where [ATable].[Member_Id] =…

Saeid
- 13,224
- 32
- 107
- 173
1
vote
1 answer
How to check if a SQL script is compatible with sql server 2000
I wrote a lot of scripts for SQL Server 2005, but now I have to rewrite those original scripts to make them work on SQL Server 2000.
I don't remember all the differences between 2005 and 2000. For instance, CTE was announced only in 2005 - and I…

Vadim Loboda
- 2,431
- 27
- 44
0
votes
1 answer
SQL query inside a SQL Script
I have a SQL script, which spools data to a file.
Sample Existing SQL script:
whenever sqlerror exit failure rollback
spool test.txt
set serveroutput on
select * from emp;
spool off
/
But, I would like to write a SQL query in this script before…

user987900
- 105
- 1
- 3
- 11
0
votes
2 answers
How to execute sql script file in java in Unix
I have this sql script that I would like to execute in a java program. It takes on 3 parameters: dropper_id, to_char(begin_dt), to_char(end_dt). How would I do this?
The program is held on a Unix server.
The sql script is also located on the Unix…

Mike
- 2,299
- 13
- 49
- 71
0
votes
1 answer
Generate Multiple Scripts from SQL Server Query Optimizer
I looked around but couldn't find an answer to this question so I figured I would ask. So I am in the process of using the SQL Server query optimizer on several long stored procedures. When the optimizer is done, that am getting lots of…

Taryn
- 242,637
- 56
- 362
- 405
0
votes
1 answer
Postgres/psql sql script: how to pass arguments as partial name
Postgres/psql 13
Hi all!
I have to create several roles with the same prefix:
create role XXX_admin...
create role XXX_owner...
create role XXX_user...
then I want to create a sql script that create those users by using a var rname=XXX:
cat…

nlarralde
- 27
- 6
0
votes
1 answer
Snowflake dynamic SQL: Storing query results as variables between executions
In Snowflake, I'd like to use the numeric result of one dynamic sql query in a second dynamic sql query:
CREATE OR REPLACE PROCEDURE DB.SCHEMA.SP_DATA_COLUMN_VALUES(table_name varchar, column_name varchar, date_column varchar)
RETURNS…

Sandra Arreola
- 1
- 2
0
votes
2 answers
Sql sort script based on one column that has odd or even value
I need help devising a sql script that will sort a bay item, based on the column value. If the level column value is even, then the bay ascends, but if the level column is odd, then bay descends. I have 12 levels, and 54 bays per level. So,…

Shuronda Hawkins
- 13
- 3