Questions tagged [scripting]

For questions about generating or using language scripts, for example scripting a database object definition.

356 questions
28
votes
5 answers

SQL Server 2012: Generate Scripts from command line

I am running SQL Server 2012. The SQL Server Management Studio has the option to right click on a database then select Tasks and Generate Scripts. Is there a way to automate that via command line somehow? I want to create a script that includes the…
Harald
  • 423
  • 1
  • 5
  • 6
27
votes
4 answers

Easy way to check connectivity to SQL Server from client

For troubleshooting purposes, I would like to be able to check if a client can connect to a SQL Server instance, independent of the application that possibly can't connect to the SQL Server. Is there an easy way (that means, not having to install…
MicSim
  • 2,531
  • 1
  • 27
  • 29
19
votes
3 answers

Alternatives to concatenating strings or going procedural to prevent SQL query code repetition?

Disclaimer: Please bear with me as someone who only uses databases a tiny fraction of his work time. (Most of the time I do C++ programming in my job, but every odd month I need to search/fix/add something in an Oracle database.) I have repeatedly…
Martin
  • 2,420
  • 4
  • 26
  • 35
19
votes
1 answer

SQL Server - Adding non-nullable column to existing table - SSDT Publishing

Due to business logic, we need a new column in a table that is critical to ensure is always populated. Therefore it should be added to the table as NOT NULL. Unlike previous questions that explain how to do this manually, this needs to be managed by…
Elaskanator
  • 761
  • 2
  • 9
  • 23
17
votes
6 answers

Redgate SQL Compare vs Visual Studio 2010 Premium/Ultimate database project

I currently use the Visual Studio Professional Edition which has the database project as a project template, but some of its features are not available, for example Schema Compare tool. The schema comparison and database update scripts generation…
rem
  • 1,555
  • 3
  • 20
  • 22
15
votes
1 answer

User-shared queries: Dynamic SQL vs. SQLCMD

I have to refactor and document a number of foo.sql queries which will be shared by a team of DB tech support (for customer configurations and things like that). There are types of tickets that come regularly where each customer have their own…
Phrancis
  • 1,320
  • 1
  • 7
  • 24
14
votes
4 answers

Script out Oracle DDL in an automated fashion

Oracle SQL Developer is able to export DDL through Tools -> Database Export... This works very well, but requires manual intervention. I know of DBMS_METADATA.get_ddl(), but have found that the export isn't perfect. I ran into issues where the…
MatthewToday
  • 325
  • 2
  • 3
  • 7
14
votes
4 answers

Scripting SQLite with dot commands

Is it possible to write scripts that contain SQLite dot commands ( vis. .read file.sql; .separator ,; .import file.csv; )? I'm building and repeatedly rebuilding an SQLite database and need to type in roughly twenty four dot command statements every…
StudentsTea
  • 341
  • 1
  • 2
  • 8
13
votes
4 answers

Dropping a constraint (index) on a column

How can I modify the type on a table that has an index on it? I tried to do an alter column on an empty table to modify the type from date time to varchar(15) and got errors saying that it had dependencies on the column (which turned out to be…
user1480
  • 231
  • 1
  • 2
  • 3
13
votes
1 answer

Does SQL Server / T-SQL support line-continuation to break up long strings?

I sometimes have a SQL script that has one or more super-long (sometimes even stupid-long) strings. Typically these are VARBINARY literals / constants that represent files / Assemblies, but occasionally they are text. The primary problem with really…
Solomon Rutzky
  • 70,048
  • 8
  • 160
  • 306
12
votes
1 answer

PostgreSQL - How to list all foreign key link to Primary key of a table

I have a table res_users with primary key id I would like to list all the foreign key link to id from all the tables in my database.
tuanngocptn
  • 223
  • 1
  • 2
  • 6
12
votes
1 answer

Why does SQL Server Management Studio not script indexes by default?

Recently I realized by default, scripting the database does not including indexes, and I have to change the option every time. Could anyone please explain the reason? Is there any insight about this default behavior, or is it just because Microsoft…
Luke Vo
  • 223
  • 2
  • 6
12
votes
4 answers

script to show all the permissions for a table

inside my database I have a procedure called spGen2_tblIE_SchedProcess_Update. when I run this script select * from sys.objects where name = 'spGen2_tblIE_SchedProcess_Update' Inside the same database I have a table called tblIE_Step when I run…
Marcello Miorelli
  • 17,274
  • 53
  • 180
  • 320
11
votes
7 answers

How do I format the output from OBJECT_DEFINITION so that it looks the same as sp_helptext?

object_definition and sp_helptext both return the source code of a stored procedure - but how can I use object_definition and get the source code including the line breaks as the sp_helptext currently does? for example in the code below I create a…
Marcello Miorelli
  • 17,274
  • 53
  • 180
  • 320
11
votes
6 answers

How can I detect broken stored procedures after a schema change?

I've modified a central table in my database, and sp_depends literally returns hundreds of results, and I'm concerned some of those stored-procedures might not compile anymore after my change. Checking one single stored procedure is easy (I just…
Brann
  • 325
  • 1
  • 3
  • 9
1
2 3
23 24