Recent Entries 10
- snippet minor 112d agoIn SQL Server, how do I save the results of a query to a txt file?In SQL Server, how do I export the results of a query to a txt file. I tried tools>options>results to file. But this appears to have saved the Messages the query generated instead of the Results the query generated.
- snippet minor 112d agoHow can I transfer the entire content of several tables to another database, not in the same network?I have a set of 12 tables, about 4 million rows total, that I need to move four times per year. The database server they are coming from can NOT directly talk to the server that they are moving to. The data has to go via SFTP file transfer. These 12 tables already exist in the destination database, but can be dropped or truncated as required. The target database will be in 'live' use during the transfer. In an ideal world, I'd love to have some script that I execute on the source server that tosses all the data into a flat file, and another script on the target server that loads the tables from the flat file. Options I've seen so far: - Exporting to CSV (although I'm not sure if having commas in the source data will cause trouble) using the import/export data wizard. I don't like how easy it would be for mistakes to happen over time, for example importing into the wrong table. - Writing powershell to export the data (CSV files again, I'd love something binary that I don't have to worry about parsing issues). - Backup and restore the database onto the server, then copy the tables that are needed. This would require copying ~100gb backups across. It would be slow, but would work. There has to be some tools out there for this sort of work! @J.D. - Why SFTP? The only approved method to bring data into this network is SFTP. Critical public safety systems, so they are rather picky. Are there other tables? Yes, this is only 12 out of many tables, entire db is roughly 100gb.
- pattern minor 112d agoExport Postgres sequences onlyIs there a way using `PG_DUMP` or any other commands to export only sequences from an existing database?
- pattern minor 112d agoMS Azure remote back up with SqlPackageI wanted to do an export of a .bacpac file from MS Azure database, from local machine, with command like this: ``` sqlpackage.exe /Action:Export /ssn:tcp:.database.windows.net,1433 /sdn: /su: /sp: /tf: /p:Storage=File ``` The DB was apparently found and the tool reported it started extracting the schema from the database, but then it fails: ``` Extracting schema Extracting schema from database Time elapsed 00:00:05.17 *** An unexpected failure occurred: .NET Core should not be using a file backed model.. ``` To my surprise, I couldn't find anything similar on the web. Is this some kind of an MS Azure bug?
- snippet minor 112d agoHow to back up an entire database to text filesIf 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 sounds hard to me. But it’s pretty easy to open up a .txt file. Could I back up my database to a text file instead, thereby making it easier to delete history out of the backups?
- pattern minor 112d agoSQL Server: SSMS "Save Results As" creates CSV that Excel manglesUsing the Save Results As option, shown below. CSV looks good! But when Excel opens/imports it: - Long strings are mangled as numbers (if the data is largely numeric) - Dates are not detected properly - My users beef about all this How do I get a query to a clean excel file (a real xls/xlsx) without dancing? (We like everything to actually in the SQL file itself... I wish we could do "SELECT INTO FILE:C:\SQLOUTPUT\DATA.XLS ...")
- pattern minor 112d agoWhat is the 131072 in the call to lo_open()ByteA to BLOB conversions typically make a call to `lo_open()`, ``` CREATE OR REPLACE FUNCTION make_lo(bytea) RETURNS oid AS $$ DECLARE loid oid; fd integer; bytes integer; BEGIN loid := lo_creat(-1); fd := lo_open(loid, 131072); -- <<< --==HERE==-- bytes := lowrite(fd, $1); IF (bytes != LENGTH($1)) THEN RAISE EXCEPTION 'Not all data copied to blob'; END IF; PERFORM lo_close(fd); RETURN loid; END; $$ LANGUAGE plpgsql STRICT; ``` In the above what is ``` fd := lo_open(loid, 131072); ``` You can see others asking this same question here, The number `131072` is some flag I couldn't find what means, and 999999999 is the max read size, but I could read the value anyway.
- pattern minor 112d agoVery large SQL Server 2016 result sets (over 75 GB) to a CSV file?What is the best way to get very large SQL Server 2016 result sets (over 75 GB) to a CSV file? The engineers need this output to look for correlations. The `bcp` route for a 73.5 GB file filled up tempdb and started crashing other applications, including the ETL process. Our users want to export up to 500 GB. What process would use the least amount of resources so that other applications keep running?
- snippet minor 112d agoHow to export database structure from Firebird?I'm doing replication and I need to export db structure from one Firebird db (dialect 3) into another. I've seen a couple tools like IBPump and FBExport, however all I can find is how to export all the data and not the structure. Any advice?
- pattern minor 112d agoUsing Postgres COPY TO for data export without overwriting fileI'm running several queries with a script and psql. I am also exporting the results to a.csv using the COPY TO command. However, this overwrites the file a.csv when I would like to instead append the results to a.csv instead. Is it possible using the COPY TO syntax perhaps there is some parameter I am missing? Or should I look at using other tools?