Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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

0
votes
1answer
24 views

Realtime Update MySQL on every Update occurred on PostgreSQL

I have a PostgreSQL for my accounting system and a MySQL database for my php website, i want to sync these two database for every update may occurred on PostgreSQL it also updates MySQL database, they ...
3
votes
3answers
58 views

Script to identify which AD accounts are no longer active [closed]

Trying to get a script that will identify which AD accounts/Windows authentication on a SQL Server are no longer active. Say perhaps an employee was released and the login would be removed from AD, ...
1
vote
1answer
22 views

how to add an extended events tracking session to SSAS?

I would prefer to have a script to achieve this, but as I am not so familiar with SSAS I am using the wizard to create an extended events session in SSAS. The way I am doing it is right clicking on ...
0
votes
0answers
21 views

SSIS Script Component within Data Flow is not processing input row

I have a transformation script component as part of a data flow. I'm clearly missing something as this is triggered on a fail of a row insert into a database table yet the script does not seem to ...
4
votes
1answer
282 views

What are the rules for using COLLATE in a query?

I am putting a script together, that gives me the permissions on database objects. SELECT permission_order=710 ,permission_type = 'Object Level Permissions' ,db = db_name(), login_=...
1
vote
1answer
55 views

is there a way to improve this query by not re calculating functions? cross apply?

when I set up replication I like to take a count of each table in the publisher, then I go to the subscriber I do the same thing in order to compare both pictures. this is the picture from the ...
0
votes
0answers
12 views

Detecting Read-only Microsoft Access Database Using Only Embedded Macros

Using VBA, I can detect a database’s read-only state using the simple expression: Not CurrentDb.Updatable. However, this is not usable when VBA has been explicitly disabled for all computers within ...
2
votes
1answer
68 views

How to script out the grant view on login permission?

I create the following login without any permissions. USE [master] GO IF NOT EXISTS (SELECT * FROM sys.server_principals WHERE name = N'Radhe') CREATE LOGIN [Radhe] WITH PASSWORD=N'...
0
votes
0answers
21 views

Flat File Database, need to read / write

I need to connect to some old C-tree Plus database files from 1998. The product is discontinued by the vendor, but still used today in current releases of software. I need to be able to both read and ...
1
vote
1answer
39 views

How do I get Postgres DO $$ to work from the bash prompt?

Postgres 9.6.9 on Linux RHEL 6.10 If I surround my DO command in double-quotes and the roles in single quotes, then bash interprets the $$, and that obviously makes the command fail. So I switched ...
0
votes
1answer
41 views

How to upgrade a MySQL database using numbered scripts based on a version field

I have a database that contains a version table with one value stored in it which is the database version number. I would like to be able to update the database version automatically using numbered ...
-2
votes
1answer
25 views

How to write a shell script to disable the database accounts from a list of user IDs

I am new to Unix scripting...I have a list of userids for terminated employees. I want to write a script that will check these userids against my databases and disable/remove the user accounts ...
0
votes
1answer
35 views

How to get a SQL value literal for arbitrary type in PostgreSQL?

I want to be able to get a valid SQL literal for any type and value. If the type is text, varchar, etc... and the value is abc I want to get 'abc'. If the type is timestamp I want quoted and ...
5
votes
1answer
305 views

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. Updating existing references that insert/update is difficult but doable, but ensuring future code/...
2
votes
1answer
312 views

I want Powershell's invoke-sqlcmd to ignore SQL execution errors

I've written a Powershell script that scripts out the appropriate SQL scripts for all databases on a server as well as creating BCP files for the contents of each. This is to allow the restoration of ...
7
votes
2answers
386 views

How to back up an entire database to text files

If it’s stupid and it works, it’s still stupid. The hullabaloo about GDPR got me thinking - if you had to go into your backups and modify/delete data, how would you do it? Cracking open a .bak file ...
4
votes
1answer
141 views

Breaking up insert statements with GO [closed]

I'm trying to build off of this answer How do I run a large script with many inserts without running out of memory? and break up a query into smaller ones with BEGIN TRANSACTION and then GO's ...
-1
votes
1answer
26 views

Can scripting be done on DB2 Connect instance?

I need to get the number of connections passing through connect server for 1 week. Can we write a script to get the details? Can we only pull the data manually? Is there any way to script it? I am ...
0
votes
0answers
12 views

how to get output in different columns for a sql select statment running through a shell script?

Currently getting all my data in one column. Formatting used in the script: set lines 500 set pagesize 100 set serveroutput on size 1000000; set verify off; set wrap on; set pagesize 1000; set ...
2
votes
2answers
182 views

SQL Server Reporting Services: Generate Scripts Programmatically

I'm looking to export SSRS reports from SSRS 2005 into SSRS 2017. I have around 100 reports to move but in total there are around 500 subscriptions across all of these reports. The Script to file ...
1
vote
2answers
124 views

script all triggers in a database

I have a few databases involved in replication as subscribers and they have triggers and are used by a different set of applications. Every time I need to reinitialise those database I need to script ...
4
votes
1answer
385 views

Sqlcmd: Invalid argument - when trying to pass a variable to sqlcmd

I'm trying to use a DOS command prompt on Server 2012R2 to run a batch with the following in it. I want to run a SQL command (sqlcmd) and return the results to the command window. This is what I'm ...
1
vote
1answer
46 views

How to make performance tests for DML

I created two multi-column indexes on a big table (~2,5 millions rows 370Mb and 621Mb with indexes). SELECT queries are very fast. Know I want to check if we have a regression for INSERT/UPDATE ...
0
votes
2answers
460 views

MySQL - Why is my BASH Script insert/update query not working correctly? [closed]

Background: I have a MySQL table that stores ip addresses for a very large amount of hosts. It's a simple table (host xyz -> ip1, ip2, ip3). These hosts will write a flat file with it's ip addresses ...
2
votes
1answer
880 views

ERROR: “sql ” is not a known variable

This must one of the dumbest questions I've ever asked here, but there must something really sick hiding in my SQL script that is blocking it from running. I'm invoking the cobertura.sql file using ...
1
vote
1answer
315 views

postgres create limited user that can select tables and columns of those tables

I have an app that automates the making of a PostgreSQL database, and also automates the creation of a database user. This database user is given limited access for security purposes, as it will be ...
1
vote
1answer
46 views

Parsing a manifest.xml of a table schema to script?

I have a manifest.xml sent to me by a vendor that accompanies some extracts they are also sending. I assume there should be a way to parse this into an actual table structure (or a script to create a ...
0
votes
1answer
326 views

Restoring multiple files to multiple database with pg_restore

I have multiple dump files and want to restore them with single command. something like this pg_restore -h localhost -p 5432 -U postgres -d gl_election gl_world gl_tourism -c "gl_election" ...
2
votes
2answers
1k views

the object definition including the line break as sp_helptext does

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 ...
-2
votes
1answer
9k views

Scripting out database user level permissions [duplicate]

I have tried to search this and was able to find few but could not find exactly the way to script out the database level permissions for a database. I am migrating this database whose logins I can ...
11
votes
1answer
448 views

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 ...
1
vote
0answers
32 views

How to save SSMS 2012 Object Explorer Scripting Settings?

I'm generating a bunch of object creation scripts in SSMS 2012, using the Object Explorer context menu. The default options for these generated scripts are not to my liking (for example, I want the ...
0
votes
1answer
555 views

Generating script in SQL server taking too long [closed]

I am making backup for my tables in the database and I am generating scripts (from task) in SQL Server Management Studio. There's about 30-40 tables that I am interested to backup including ...
0
votes
1answer
65 views

Create a table with the same constraints,triggers,indexes, and statistics for house-keeping table

I have a current database with few hundred tables, say, tables A,B,C... and I want to create the same tables with the same constraints,triggers,indexes, and stats as the original tables. I know I ...
0
votes
2answers
59 views

How to Repair “Orphaned” Database in SQL Server 2016

So, in my haste, I ran a script to create a database but I did not select the full script before running it. I ended up with a bunch of tables without a "parent" database. Then I created a database ...
0
votes
1answer
215 views

MongoDB scripts triggered by cron - how to achieve reasonable password security

We would like to do nightly purging of old data out of our mongo cluster. First thought is to write shell script which connects to one of the mongos and issues a remove instruction. evalString='db.fs....
2
votes
0answers
353 views

SQL Central Management Server (CMS) with Powershell [closed]

I want to run a query (test_input.sql) on my CMS Registered Server Group (multiple sql server inside) and then I will insert results to my table. My Powershell query like below but it doesn't work (...
1
vote
1answer
378 views

Passwordless mysqldump via shell script in /etc/cron.daily

I'm aware that there are dozens of questions similar to this, but it seems none has a definitive answer to my problem, so that's why I'm posting this... I hope in the right place. The problem: I ...
5
votes
2answers
209 views

SSMS constraint script: Purpose of second alter table statement?

SSMS scripts Foreign Key constraints as two statements: ALTER TABLE {table} WITH CHECK ADD CONSTRAINT {constraintname} {constraint spec} GO ALTER TABLE {table} CHECK CONSTRAINT {constraintname} GO ...
5
votes
1answer
732 views

Using X at the end of a SELECT in SQL Server Script?

I'm relatively new to T-SQL and looking through my predecessors scripts, I found a line I can't quite parse. It's a hard thing to look up on my own. Hoping for advice. This line occurs inside a ...
1
vote
1answer
87 views

Arguments for MongoDB backup with OpsManager or mongodump?

I have a replica set of two MongoDB nodes running (with an arbiter) and I am now wondering about the best backup and recovery solution. I am aware of the official documentation, but it does not ...
0
votes
1answer
82 views

how to take backup of a child table with foreign key dependency in mysql using bash [duplicate]

Parent table : p_id, t_id, name , salary Child table : c_id, t_id , age key : Child.t_id=Parent.t_id While taking backup i would like to take pull only the matching records from Child table . How can ...
-1
votes
1answer
101 views

Alert when the restore verify only fails on the latest backup of all the database

I need a way to validate the backup files of all the database on weekly basis. A script which should run Restore Verify Only on the latest backup file of all the database and incase the backupset in ...
2
votes
0answers
246 views

SSIS Script Component errors sporadically with the same code

I have a SSIS Data Flow Task that takes CSV output (from a flat file connection) and passes that to a Script Component. When I run the task I get the following error: Script Component has ...
0
votes
1answer
77 views

Is wrapping only possible for package bodies?

I am using oracle 11gR2 database in which I was trying to wrap my scripts. I read the documents and tried to wrap a sql script which contains a create table statement. I used below commands: wrap ...
3
votes
2answers
4k views

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 ...
0
votes
1answer
623 views

Existing DB2 connection does not work inside a script

I connected to the DB2 instance, and I can successfully verify that the connection exists: db2inst1@hostname:/tmp$ db2 connect Database Connection Information Database server = DB2/...
1
vote
1answer
70 views

Script not working after adding try and catch

I have a working script that I modified to work with SQLCMD since I need to invoke this script remotely. Here is my script: :ON ERROR EXIT USE [master] GO BEGIN TRY /****** Declare Database name **...
1
vote
1answer
117 views

Automation approach to executing Shell scripts and performing checks on an Oracle DB

I am in the process of producing an automation framework that will: Check Oracle tables for entries, such as IDs and status numbers Log onto a UNIX box via Putty and switch to a directory where the ...
1
vote
1answer
2k views

How to preserve sqlplus session in shell script

I am trying to insert queries from a sql file in shell script using sqlplus. Now, some queries can fail because of incorrect schema. So I want to commit all transactions only if all queries succeed. ...