Database Administrators
Q&A for database professionals who wish to improve their database skills
Latest Questions
0
votes
1
answers
140
views
How to execute complete database script without checks on objects existence
I'm working on a customer data archiving. I created a complete database script to prepare the new database for archiving data with the same DB schema of the production one. At the moment I'm preparing a Test environment to verify all the steps we will execute in in production later, but the script i...
I'm working on a customer data archiving.
I created a complete database script to prepare the new database for archiving data with the same DB schema of the production one.
At the moment I'm preparing a Test environment to verify all the steps we will execute in in production later, but the script is, obviously, raising a lot of errors because of missing external database's views, functions and stored procedure being referred to.
Is it possible to switch off objects existence during the script execution, so I can create the complete database schema to make my tests?
---
I decided to proceed with tests about restoring the whole production database and then clear all tables data.
To clear the data I will try suggestions I found in replies to this question in Stack Overflow, to be precise these two:
- https://stackoverflow.com/a/12719464/21116580
- https://stackoverflow.com/a/22527902/21116580
I will come back as soon as I'll complete my tests with the results.
El See
(1 rep)
May 20, 2024, 03:29 PM
• Last activity: Aug 3, 2025, 05:05 AM
0
votes
1
answers
910
views
Script server level user securables onto another server
I have restored a backup of the live DB on a test SQL Server VM. Then I scripted the server level SQL users and restored them on the test SQL Server and fixed the orphaned user situation. But the user securables were not scripted - is there a way to do this?
I have restored a backup of the live DB on a test SQL Server VM.
Then I scripted the server level SQL users and restored them on the test SQL Server and fixed the orphaned user situation.
But the user securables were not scripted - is there a way to do this?
variable
(3590 rep)
Jun 22, 2022, 06:10 AM
• Last activity: Aug 2, 2025, 08:09 PM
0
votes
1
answers
980
views
Oracle database 12C restore script
i'm trying to create backup restore script . in short my backup script creating new directory every day from the operating system level and then backup the database using the directory created i tried the below script but it seems RMAN doesn't recognize the controlfiles here is my script **#RMAN RES...
i'm trying to create backup restore script .
in short my backup script creating new directory every day from the operating system level and then backup the database using the directory created
i tried the below script but it seems RMAN doesn't recognize the controlfiles
here is my script
**#RMAN RESTORE SCRIPT**
#!/bin/bash
#Environment Variables
ORACLE_HOME=/u01/app/oracle/product/12.2.0.1/dbhome_1
ORACLE_SID=cdb11
PATH=$PATH:$ORACLE_HOME/bin
DD=
date +%Y-%m-%d-%H-%M
export ORACLE_HOME ORACLE_SID PATH DD controlfile backupsets
controlfile=/ArchiveDBBackup/DAILY_RMAN/${DD}/CDB1_CONTROLFILE
backupsets=/ArchiveDBBackup/DAILY_RMAN/${DD}/
export controlfile backupsets
LOGFILE=/RMAN/log/DAILY_FULLBKP_RESTORE_date +%Y%m%d
.log
rman target / LOG $LOGFILE RMAN-03002: failure of restore command at 07/04/2021 09:35:57
RMAN-06172: no AUTOBACKUP found or specified handle is not a valid copy or piece
any idea how can RMAN recognize linux variables ? or anyway to achieve the restore with those variables ?
Seif Hassan
(11 rep)
Jul 4, 2021, 08:51 AM
• Last activity: Jul 29, 2025, 02:02 AM
0
votes
1
answers
429
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 are on linux operating system(ubuntu), How can i do this work?
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 are on linux operating system(ubuntu),
How can i do this work?
AHAD
(1 rep)
Oct 17, 2018, 12:52 PM
• Last activity: Jun 28, 2025, 05:03 AM
2
votes
1
answers
59
views
DBeaver @include using a variable for filename not working
I am trying to write a script to run in DBeaver (Version 24.0.0) it determines what schema update scripts to run based on a table in the database that records the schema updates already run. It then tries to use the dbeaver @include to run the needed update scripts. It looks something like: ** **@se...
I am trying to write a script to run in DBeaver (Version 24.0.0) it determines what schema update scripts to run based on a table in the database that records the schema updates already run. It then tries to use the dbeaver @include to run the needed update scripts.
It looks something like:
**
**@set db_dir = ''
do $$
DECLARE
file upgrade_file%ROWTYPE;
file_location text;
BEGIN
FOR file in (select * from upgrade_files) loop
file_location = ${db_dir} ||file.filename;
raise info 'file: %', file_location;
@include ${file_location}
end loop;
end $$**;
**
If I run this I get "Syntax error at or near @".If I comment out the @include statement in the for loop it runs fine and prints out the correct filenames, including path, to be run. Any help figuring out what I am doing wrong or another approach would be appreciated.
Sarah Holley
(21 rep)
Jun 26, 2025, 05:09 PM
• Last activity: Jun 26, 2025, 05:49 PM
1
votes
2
answers
519
views
Script to get definitions of table types and Sequences
I need to get the definition of some objects in the SQL server. I got the definitions of stored procedures, functions, views and triggers from sys.sql_modules. But, I don't know how to get that of user-defined table types and of sequences. I am trying to create this in another database and automate...
I need to get the definition of some objects in the SQL server. I got the definitions of stored procedures, functions, views and triggers from sys.sql_modules.
But, I don't know how to get that of user-defined table types and of sequences. I am trying to create this in another database and automate this process.
Does anyone know how to get the definition of table types and sequences?
Viz Krishna
(109 rep)
Nov 25, 2022, 09:11 AM
• Last activity: Jun 3, 2025, 02:54 PM
1
votes
2
answers
334
views
Silence Sqlplus Login Message but Retain Echo
Running a series of automated checks on our databases for the security folks checking our STIG compliance. Mostly simple stuff like certain parameters turned off, etc. We're in the stone ages, so this is being done with Sqlplus scripting to populate the reports. Using sqlplus -S to filter out that u...
Running a series of automated checks on our databases for the security folks checking our STIG compliance. Mostly simple stuff like certain parameters turned off, etc. We're in the stone ages, so this is being done with Sqlplus scripting to populate the reports.
Using sqlplus -S to filter out that unnecessary login message, but the security folks would also like the command with the finding details instead of just the output. With sqlplus -S, the output is
VALUE
------
FALSE
whereas we want
Select blah blah;
VALUE
------
FALSE
Set echo on doesn't fix this, even when nesting the query in a sql script and run with @. I'm assuming the S option overrides the echo setting. Wondering if there's an option I'm not familiar with or if I just need to work around it.
Jeff Bauersfeld
(335 rep)
May 18, 2021, 08:33 PM
• Last activity: May 31, 2025, 03:01 PM
0
votes
2
answers
284
views
Command line command to read Oracle Database export Success Message In log File
We have several oracle 19c servers with daily exports. I would like to find a way to run a command to read the export log file to find the success message for the day. e.g. I would like to putty into the linux server have a command I can copy and paste that will read the daily export log file and te...
We have several oracle 19c servers with daily exports. I would like to find a way to run a command to read the export log file to find the success message for the day. e.g. I would like to putty into the linux server have a command I can copy and paste that will read the daily export log file and tell me in one command/output that the export was successful or not? or any better ideas to automate reporting that daily exports are successful on 40+ servers?
crcoder
(1 rep)
Jan 7, 2023, 11:42 PM
• Last activity: May 17, 2025, 07:07 AM
2
votes
0
answers
22
views
Programmatically create a Role with Permissions within pgAdmin’s internal user management
I am asking about [*pgAdmin*][1] internal [user management][2], not *Postgres* users-and-roles. For teaching a beginning database class, I am trying to procedurally configure *pgAdmin* in Server Mode, using shell scripts, *Podman*, etc. In addition to the `Administrator` and `User` roles, I want to...
I am asking about *pgAdmin* internal user management , not *Postgres* users-and-roles.
For teaching a beginning database class, I am trying to procedurally configure *pgAdmin* in Server Mode, using shell scripts, *Podman*, etc. In addition to the
I want to procedurally create a Role that effectively has some of those checkboxes unchecked.
Administrator
and User
roles, I want to create a Student
role with restricted permissions.
The setup.py
feature offers a command-line interface for configuring pgAdmin. It offers commands like:
- add_user
- get_role
👉🏽 Is there some procedural way to define a Role with Permissions?
I need a console command equivalent for the *Permissions* tab in the *pgAdmin* GUI:

Basil Bourque
(11188 rep)
May 16, 2025, 06:07 AM
• Last activity: May 17, 2025, 03:37 AM
1
votes
1
answers
286
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 scripts. If the database is version "6" and I have a dir of scrips numbered inconsistently as per the...
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 scripts.
If the database is version "6" and I have a dir of scrips numbered inconsistently as per the below:
001.sql, 02.sql, 3.sql, 4script.sql, 5.sql, 6.upgrade.sql, 7.sql, 8.data.sql, 009.updated.sql
What is the best way to only run scripts which are numbered greater than the version number and to do this in sequence?
Should I use an SQL script or create a bash script?
I am a little stuck on how to approach this so any pointers or advice will be much appreciated...
Mark Smith
(131 rep)
Aug 5, 2018, 08:32 AM
• Last activity: May 9, 2025, 11:08 PM
0
votes
1
answers
964
views
Error with dbatools
Trying to export SQL Objects via DBAtools in Powershell. Get-DbaAgentJob -SqlInstance 'TestServer01' -Job 'mydatabase-daily-backup' | Export-DbaScript -FilePath C:\temp\mydatabase-daily-backup.sql The same script working fine and exporting the job details. But, not working on a few servers, and retu...
Trying to export SQL Objects via DBAtools in Powershell.
Get-DbaAgentJob -SqlInstance 'TestServer01' -Job 'mydatabase-daily-backup' | Export-DbaScript -FilePath C:\temp\mydatabase-daily-backup.sql
The same script working fine and exporting the job details.
But, not working on a few servers, and returns the below error/warning
> WARNING: [06:05:42][Get-DbaAgentJob] Failure | The value's length for key 'Data Source' exceeds its limit of '128'.
Prakash
(1 rep)
Sep 13, 2023, 12:12 PM
• Last activity: May 5, 2025, 12:08 AM
1
votes
1
answers
316
views
Cannot script stored procedure while restoring another copy of current db
I have some large DB that I need to restore to another db from time to time, this process take some time to conclude. The annoying thing I found out in last version of SSMS is that I cannot script any sp of the current db while I do this restore. In my case I have the current db named `FleetXS` that...
I have some large DB that I need to restore to another db from time to time, this process take some time to conclude. The annoying thing I found out in last version of SSMS is that I cannot script any sp of the current db while I do this restore.
In my case I have the current db named
I have no need to open the database
> Microsoft SQL Server 2019 (RTM-CU10) (KB5001090) - 15.0.4123.1 (X64)
> Mar 22 2021 18:10:24 Copyright (C) 2019 Microsoft Corporation
> Standard Edition (64-bit) on Windows Server 2016 Datacenter 10.0
> (Build 14393: ) (Hypervisor)
- SQL Server Management Studio 15.0.18390.0
- SQL Server Management Objects (SMO) 16.100.46521.71
- Microsoft Analysis Services Client Tools 15.0.19714.0
- Microsoft Data Access Components(MDAC) 10.0.19041.1
- Microsoft MSXML 3.0 6.0
- Microsoft .NET Framework 4.0.30319.42000
- Operating System 10.0.19043
I do not use SSMS to do the restore, I use my own script. There are two backups to restore, full + diff. I do full with norecovery and diff with recovery.
FleetXS
that is online and is in use and I do the restore of backup of this db with the date of 2 days ago in other db named Fleetxs_Restore
. For all the time of the restore it's not possible to script any sp of db FleetXS
with the weird error
> Cannot open database "FLEETXS_restore" requested by the login. The
> login failed. Login failed for user 'anna'. (Microsoft SQL Server,
> Error: 4060)

FLEETXS_restore
that even is not actual to date, I operate within my current database FleetXS
that is online, why on the earth my login "requested db FLEETXS_restore
"? Is there any workaround or should I wait for hours when the restore finishes to be able to get the text of sp of **another** database?

sepupic
(11277 rep)
Nov 5, 2021, 10:43 AM
• Last activity: Apr 28, 2025, 09:03 PM
2
votes
1
answers
325
views
My SSMS is bringing wrong object in "Script Stored Procedure as" > "CREATE To" > "New Query Editor Window"
When I go to Object Explorer and expand down to Stored Procedures (or Tables), right-click on one of them and choose "Script Stored Procedure / Table as" > "CREATE To" > "New Query Editor Window", it takes a while (becomes unresponsive) and then brings another object (function / table). If I do the...
When I go to Object Explorer and expand down to Stored Procedures (or Tables), right-click on one of them and choose "Script Stored Procedure / Table as" > "CREATE To" > "New Query Editor Window", it takes a while (becomes unresponsive) and then brings another object (function / table).
If I do the same but choose other action (for instance, "ALTER" for Procedures or "DROP And CREATE") instead of CREATE, it brings the correct object.
It started to behave that way without any clear reason, except for, perhaps, the last SSMS update. I thought I had successfully used CREATE just a few minutes before noticing that error, but later I realized I've used ALTER and not CREATE.
I've tried different databases and even different servers, with the same results. I've already restarted the machine but it didn't change anything. I've also asked a coworker to do the same steps and he didn't get any errors in his machine.
Obs.: It has nothing to do with permissions; it is also happening with my local SQL Express installation (where I have full access).
Is there any template for those script generation? If yes, where are they stored? If not, how can I possibly fix that?
Version information:
Microsoft SQL Server Management Studio = 13.0.16100.1; Microsoft Analysis Services Client Tools = 13.0.1700.441; Microsoft Data Access Components (MDAC) = 10.0.14393.0; Microsoft MSXML = 3.0 6.0; Microsoft Internet Explorer = 9.11.14393.0; Microsoft .NET Framework = 4.0.30319.42000; Operating System = 6.3.14393;
Alexandre
(165 rep)
Dec 21, 2016, 10:25 PM
• Last activity: Apr 25, 2025, 08:05 PM
1
votes
1
answers
2360
views
Oracle - Delete dmp files from ASM diskgroup
I want to delete my export files daily from ASM diskgroup with a crontab job. I want to prepare a script for it. ASMCMD> ls exp1.dmp exp2.dmp exp3.dmp exp4.dmp ASMCMD> pwd +DATA/EXP How can I prepare this script? I prepared a template for it, but I couldn't script it. ``` set_gridenv asmcmd cd +DATA...
I want to delete my export files daily from ASM diskgroup with a crontab job. I want to prepare a script for it.
ASMCMD> ls
exp1.dmp
exp2.dmp
exp3.dmp
exp4.dmp
ASMCMD> pwd
+DATA/EXP
How can I prepare this script? I prepared a template for it, but I couldn't script it.
set_gridenv
asmcmd
cd +DATA/EXP
rm -rf exp*.dmp
exit
jrdba
(55 rep)
Sep 21, 2020, 10:45 AM
• Last activity: Apr 8, 2025, 03:11 AM
0
votes
0
answers
24
views
Periodic copying, synchronizing, forwarding and merging of SQL database tables with MSSQL Express?
There is a modification project in our Process Plant related to SCADA application (Process Automation System) and I am looking for reliable advice/ suggestions from experienced members related to SQL Database Management. **Background:** We have multiple Workstations each running Stand-alone SCADA ap...
There is a modification project in our Process Plant related to SCADA application (Process Automation System) and I am looking for reliable advice/ suggestions from experienced members related to SQL Database Management.
**Background:** We have multiple Workstations each running Stand-alone SCADA application with SQL Express for writing Real-time Alarms to SQL DB and occasional reading. We need to forward these Alarms SQL DB (Table only) from all Workstations to Centralized Station, merge all Alarm Tables into one, and then import to SQL Express DB on Centralized Station for Read-Only Purpose. These tasks need to be automated and triggered at appropriate frequency (for eg. every 1 Hour).
Please note that all Workstations are Workgroups and Stand-alone.
Please also note that communication between Workstations and Centralized Station is strictly uni-directional i.e. Workstation -> Centralized Workstation (so no option for SQL Server Replication).
***
### My Rough Plan
#### On Each Workstation:
1. Duplicate the Production_DB to Offline_DB (in same SQL Server Instance)
2. Synchronous/Asynchronous update of Alarms Table from Production_DB to Offline_DB.
3. Periodic Conversion of the Alarms Table from Offline_DB to CSV.
4. Forwarding the CSV to Centralized Workstation.
#### On Centralized Workstation:
5. Creating Workstation_DB for each Workstation in SQL Server instance.
6. Converting and importing CSV file in each Workstation_DB to Alarms Table.
7. Creating one Central_DB and merging all Workstations Alarms Table to one Table.
8. Assign Central_DB to SCADA Application on Central Workstation.
Please advise if the rough plan needs correction or optimization.
I have no background knowledge of SQL scripting and I would be grateful if someone also guide me through the execution of each step in SQL (excluding step 4 and step 8).
Hmbl3Lrnr
(1 rep)
Feb 18, 2025, 08:31 AM
• Last activity: Feb 18, 2025, 08:33 AM
0
votes
1
answers
102
views
How to automate the dropping of databases?
Working on a script to [drop databases][1]. In some of the environments our databases are regularly restored from live, [replication][2] (merge or transactional) established, processes run and tested, then, the databases need to be dropped, as all of the development has been deployed to live, now an...
Working on a script to drop databases .
In some of the environments our databases are regularly restored from live,
replication (merge or transactional) established,
processes run and tested,
then, the databases need to be dropped, as all of the development has been deployed to live,
now another cycle starts.
as part of automating the dropping of the database
so far I came out with this script below:
select
DROP_DB_SCRIPT='use master;' + char(13)
+ case when source_database_id is not null -- this is a database snapshot
then ''
else
' alter database ' + name + ' set single_user with rollback immediate ' + -- put db in single user mode
case when (sb.is_published = 1 or sb.is_merge_published = 1)
then 'EXEC sp_removedbreplication ' + '''' + name + '''' -- remove db from the replication
else ''
end +char(13)
end +char(13) +
' drop database ' + quotename(name) +char(13)
,*
from sys.databases sb
where database_id >= 5
and is_distributor= 0
The script above will not do anything other than produce a script that I can use to drop a desired database or set of databases.
it takes into consideration replication, (you need to remove the replication separately), and if the database is a database snapshot , which is a different thing .
I have not considered the following:
Should an OFFLINE database be SET EMERGENCY before dropping?
the question here is:
Is there anything, any check, that you can see I should have added but have not?
I have dealt with 2 things:
1. database is a snapshot
2. database is involved in replication
I have not dealt with:
1. Database is part of an availability group (in that case I would need to remove it from the AG first)
2. anything else that you can see?
Marcello Miorelli
(17274 rep)
Jan 20, 2025, 10:51 AM
• Last activity: Jan 21, 2025, 01:14 PM
2
votes
2
answers
453
views
How to order databases by size? (For use in full backups)
Recently, I've been trying to make our company's full backup process more efficient. In order to do this, my team has decided that instructing the backup job to tackle the full backups starting with the smallest databases and ending with the largest is the best way to meet our objectives. To do this...
Recently, I've been trying to make our company's full backup process more efficient. In order to do this, my team has decided that instructing the backup job to tackle the full backups starting with the smallest databases and ending with the largest is the best way to meet our objectives. To do this, I added a cursor to the existing job to set the database order before running:
DECLARE @db_name VARCHAR(100), @db_id INT, @db_size INT;
PRINT '**********Order Databases by Size**********'
PRINT ' ';
DECLARE DB_by_Size CURSOR FAST_FORWARD FOR
SELECT db.[name], db.database_id, mf.size
FROM sys.databases AS db INNER JOIN sys.master_files AS mf ON db.database_id=mf.database_id
WHERE mf.[type] 0 AND db.name 'tempdb'
ORDER BY mf.size;
OPEN DB_by_Size
FETCH NEXT FROM DB_by_Size
INTO @db_name, @db_id, @db_size
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC BackupScripts.dbo.DatabaseBackup @Databases = @db_name,
@Directory = N'\\*****\Backups',
@BackupType = N'Full',
@Compress = N'Y',
@LogToTable = N'Y',
@Period = N'Weekly',
@Execute = N'Y'
FETCH NEXT FROM DB_by_Size
INTO @db_name, @db_id, @db_size
END;
CLOSE DB_by_Size;
DEALLOCATE DB_by_Size;
GO
I've been running the job like this for a couple weeks and observing the run times for each database in the command logs:
USE BackupScripts
SELECT *
FROM dbo.commandlog
WHERE StartTime >= 'yy-mm-dd 00:00:01.000' AND StartTime 'UPDATE_STATISTICS' AND CommandType = 'BACKUP_DATABASE' AND Command NOT LIKE '%\Nightly\%'
ORDER BY StartTime DESC
When I look at the results for the above query, the longest-running backups aren't happening at the end like I expected. The run times seem to be pretty arbitrary instead of more or less from shortest to longest like I was trying to do. I think this has something to do with the way I'm measuring size (correct me if I'm mistaken here), so I'm thinking
mf.size
doesn't seem to be a good measure to accomplish what I'm going for.
Does anyone know a better table to pull my database size information from instead of sys.master_files
? Or a better way to gauge how long a database will take to run a full backup before it actually runs the job? I've been hunting around for awhile, and can't get an accurate read from the tables I'm finding. Thanks!
hemuxin
(21 rep)
Oct 9, 2017, 02:18 PM
• Last activity: Jan 18, 2025, 12:11 PM
8
votes
4
answers
17996
views
Restore All Databases Script
I am migrating SQL Server DBs to a new instance. I have been told that it is possible to dynamically build a RESTORE script from available backups in the system catalog. Does anyone know of a sample script to do this? Thanks!
I am migrating SQL Server DBs to a new instance.
I have been told that it is possible to dynamically build a RESTORE script from available backups in the system catalog.
Does anyone know of a sample script to do this?
Thanks!
K09
(1454 rep)
Jul 31, 2014, 03:18 PM
• Last activity: Jan 16, 2025, 02:37 PM
0
votes
1
answers
4204
views
Read and Get Data from ExcelFile using powershell
I'm starting with powershell and this time. I have to read all the values from a excel file In this case from a specific sheet. The ultimate goal of this task is to get the values from two columns and then save this values and export to a SQL Table because I have a StoreProcedure to read the table a...
I'm starting with powershell and this time. I have to read all the values from a excel file
In this case from a specific sheet.
The ultimate goal of this task is to get the values from two columns and then save this values and export to a SQL Table because I have a StoreProcedure to read the table and then create all extended properties needed in one database with thouse values
This is the code but I not able to get correctly the data from excel
$Excel = New-Object -ComObject Excel.Application
$Path = '' #I'm using a shared folder
$Workbook = $Excel.Workbooks.Open($Path)
$workSheet = $Workbook.Sheets.Item(4) #The number is for because the excel file has 4 sheets
#and the sheet desired is the last one
$Output = @()
$Output = [pscustomobject][ordered]@{ #I think with this I could go through the table but I
#would have to calculate the coordinates first.
Rol = $Worksheet.Range("A4").text
Member = $Worksheet.Range("B4").text
}
Example of how looks the sheet
| Rol | Member | Description |
|:---- |:------:| -----:|
| Admin | name + email | Description of the rol |
| Data Lead | name + email |Description of the rol |
| Arquitect | name + email | Description of the rol |
| DBA | name + email | Description of the rol |
| QA | name + email | Description of the rol |
So, my intention is go through the table and get the date as array but to take into account.
Sometimes a role can have several members associated with it and that's means more rows in member column
Best Regards and thanks in advance
SakZepelin
(21 rep)
Aug 13, 2021, 10:42 AM
• Last activity: Jan 10, 2025, 11:05 AM
1
votes
1
answers
765
views
Numbering rows consecutively for a number of tables
I have a number of tables, all containing attributes `aid,bid,cid`, and `xid` of type integer, other attributes may differ. For every (given) table `T`, I would like to order the rows according to `aid,bid,cid` ascending and update column `xid` with incremented values starting with 0. What's the bes...
I have a number of tables, all containing attributes
aid,bid,cid
, and xid
of type integer, other attributes may differ. For every (given) table T
, I would like to order the rows according to aid,bid,cid
ascending and update column xid
with incremented values starting with 0. What's the best way to achieve that?
My current solution involves:
- selecting table T
- openining a cursor over the ordered tuples of a table
- assigning the autoincrement value to xid
- inserting the tuple into a temporal table T_temp
- deleting all records from T
- inserting all records from T_temp
into T
Since the tables have different schemas, I programmed half of the code in PL/pgSQL
and half of the code with bash scripting.
**Question 1:** Any comments how to have it program that in pure PL/pgSQL?
**Question 2:** Any comments how to implement that more elegantly?
arthur
(888 rep)
Dec 13, 2013, 12:31 PM
• Last activity: Nov 1, 2024, 02:19 AM
Showing page 1 of 20 total questions