Sybase Anyware. SQL query to determine DB version - sybase

What query or command to determine Sybase SQL Anyware version?
I use sqlsh + freetds as interactive client (in Emacs).

For databases, you can use the SYSHISTORY system view to find out what version the database was created at.
select version from SYSHISTORY where object_id = OBJ_ID_OF_DB
If you databases were migrated from earlier installations, and don't show the version number you expect, you probably could just create a small database, and take a look at the version history information.

Related

Sybase BCP vs MS SQL BCP

I have a multi-database setup that I need to work with and both have their own bcp versions that do not act the same way. Plus both are in my %PATH% and the Sybase one is listed before the MS SQL exe so calling "bcp" from the command line always hits the Sybase exe.
First, the versions are "different":
Sybase BCP:
Sybase CTBCP Utility/15.0/P-EBF17890 ESD #24/PC Intel/BUILD1500-123/OPT/Thu May 13 02:45:43 2010
(for Adaptive Server Enterprise/15.7/EBF 23008 SMP SP130 /P/RS6000/AIX 6.1/ase157sp13x/3819/64-bit/FBO/Sat Aug 23 02:49:06 2014)
MS SQL BCP:
Version: 11.0.2100.60
(queries hitting SQL 2008 R2 and 2012 SP3 dbs)
They definitely do not handle output to a file the same way and the docs for each show that. Everything I read on bcp says that bcp should work the same between Sybase and MS SQL but I have to call the full MS SQL bcp.exe path for a queryout call to MS SQL because the Sybase bcp does not support the queryout the same way.
My process uses a batch script to call multiple queries that hit the Sybase DBS and then MS SQL databases to output data to a staging db, will I always have to differentiate between the Sybase and MS SQL bcp's or can I use just one without issue? If so, which one is the "right" one to use (not trying to spark a debate here on which is better). Also, I see nothing showing that the version numbers have any relation what so ever so knowing which is the "latest" and using that one is proving difficult.
Keep in mind that MS SQL Server was identical to Sybase ASE back in 1994 (the called Sybase SQL Server), but after that, they slowly started to move apart. So the concept of BCP is still there and similar, but the details are different.
For one thing, do not expect to be able to interchange client tools for these databases: Microsoft has made changes to the TDS protocol that makes it impossible to connect a client to the other vendor's databases.
If you've got a clash between to two executables with the same name, common solutions include (i) explicitly specifying the executable's pathname (ii) setting the right environment variables before calling one or the other executable (iii) renaming one of the executables. YMMV.

Migrate Sybase SQL Server/11.0.3.2 ( Sybase 11.0) to Sybase 11.9.2

I would like to migrate a instance of SQL Server/11.0.3.2 to Sybase 11.9.2 (i want use SSMA after that). There is no documentation on this subject on the web because it's too old (1997).
I only want migrate 3 databases of my instance. I try to dump a db to Sybase 12.5.4, not work, ddlgen not work on 11.0.3.2. With the system table, i can recreate the SQL script for table, view, procedure... and then i bcp the data. But i think it's not a good way, it's too long and not safe...
An other solution: upgrade the server to 11.9.2 (or more), but as i say, i only want migrate 3 databases.
If sombody have an other way to do that, it's will be a great help.
Thank in advance.
You should be able to take a database dump from 11.0.3 and load it into a later ASE version. It is not formally supported, but I have done this successfully for ASE 12.5.

How to test if my Oracle DB version supports the PIVOT function?

I need to work out a way to determine if Oracle is 11g or newer, because essentially I need to know if the DB I'm running on supports PIVOT.
Getting the version number ifself is not that difficult, so I've got:
select * from v$version
Unfortunately, this does not give a simple number, but 5 records including stings and various different version numbers:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production
CORE 10.2.0.5.0 Production
TNS for Linux: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production
So, is there a way to determine if my Oracle is 11g or higher, or even better, if the DB supports the PIVOT statement?
Thanks!
As one of the methods of determining whether your Oracle version supports PIVOT or not is to query the V$RESERVED_WORDS view to find out if the reserved word PIVOT is there or not.
SQL> select keyword
2 from v$reserved_words
3 where keyword = 'PIVOT'
4 ;
KEYWORD
---------
PIVOT
If you are writing a code (as you've mentioned in the comment to the #Ben's answer, quote I'm creating a procedure that generates and executes SQL statements for a datamart) that is going to take advantage of version specific features you could (and it's preferred approach) use dbms_db_version package for conditional compilation. For instance:
create or replace some_proc
is
begin
$if dbms_db_version.ver_le_10_2 -- for example
$then
-- features up to 10g r2 version
$else
-- current release
$end
end;
I hope followings will help you
Check Oracle Version
Identifying Your Oracle Database Software Release
I'm a little confused about why you wouldn't know what version of Oracle you're using already.
However, you can use the system view PRODUCT_COMPONENT_VERSION to get the current version. It's what Oracle recommends to check your current release number.
select * from PRODUCT_COMPONENT_VERSION
So you can see the output; it works in SQL Fiddle as well.

Restore SQL Server 2008 database to SQL Server 2000

I have to move an entire database from a SQL Server 2008 machine to a SQL Server 2000 machine.
I created a backup using Management Studio 2008, copied it to the hard drive of the 2000 box, and from withing Management Studio 2008, I choose Restore Database to the 2000 box.
I get an error message stating, "The media family on device ... is incorrectly formed. SQL Server cannot restore this media family".
If I use Enterprise Manager 2000 I get the same error.
Is there a way to move a whole database from the newer SQL server to the older?
The only thing I can think of is to recreate the whole structure and then copy data from a live database. So, create scripts that will create the tables, views, and sp's, and then create scripts to copy the data from the existing database.
As others already said there is no default way to do this. It’s just not supported. Here are more extensive details on how to do this properly and avoid any migration issues.
You need to generate scripts for structure and data and then execute these on SQL 2000 (like others already said) but there are couple things to take into account.
Generate scripts in SSMS
Make sure to check option for scripting data for SQL 2000 to avoid issues when trying to create something like geography type column on SQL 2000.
Make sure to review execution order of scripts to avoid dependency based errors
This is a great option for small to medium size databases and requires some knowledge of SQL Server (dependencies, differences between versions and such)
Third party tools
Idea is to use third party database comparison tools such as ApexSQL Diff or Data Diff
Good side is that these will take care of script execution and differences between versions
Not so good is the fact that you’ll need to pay for these after trial ends
I’ve used these two tools successfully but you can’t go wrong with any other tool on the market. Here is a list of other tools in this category.
you can't move backups from a newer version to an older, in that case you can script your database, execute it in the 2000 box, then you can use the standard data transfer to transfer any data you want
Provided you have a network connection between the machines use SSIS. Much easier and a lot less messing around.
You can use Script Generator for your database and then select in the properties form : General-> Script for server version : SQL Server 2000.
The script generator will show you things which not compatible with your server version.
I've heard you can only do it by generating the SQL statement dump from the DB administrator tool and re-running those queries on the target older database.
You can generate a script that will recreate all the objects and transfer all the data...as long as everything in the db is valid in SQL 2000. So no ROW_NUMBER(), no PARTITION, no CTEs, no datetime2, hierarchy or several other field types, no EXECUTE AS, and lots of other goodness. Basically, there's a pretty good chance it's not possible unless your db is pretty basic.
We got a similar situation. A very low-tech but handy solution is:
backup and truncate the tables in SQL 2000.
create a LINKED server in SQL 2008, pointing to SQL 2000
run a select query at sysobjects to generate a query script for insert into LINKED SERVER.table select * from table
execute query script.

migrate data from MS SQL to PostgreSQL?

I've looked around and can't seem to find anything that answers this specific question.
What is the simplest way to move data from an MS SQL Server 2005 DB to a Postgres install (8.x)?
I've looked into several utilities like "Full Convert Enterprise", etc, and they all fail for one reason or another, ranging from strange errors that make it blow up to inserting nulls rather than actual data (wth?).
I'm looking at a DB with all table except for a single view, no stored procs, functions, etc.
At this point I'm about to write a small utility to do it for me, I just can't believe that's necessary. Surely there's something somewhere that can do this? I'm not even too worried about cost, although free is preferable :)
I don't know why nobody has mentioned the simplest and easiest way using robust MS SQL Server Management Studio.
Simply you just need to use the built-in SSIS Import/export feature. You can follow these steps:
Firstly, you need to install the PostgreSQL ODBC Driver for Windows. It's very important to install the correct version in terms of CPU arch (x86/x64).
Inside Management Studio, Right click on your database: Tasks -> Export Data
Choose SQL Server Native Client as the data source.
Choose .Net Framework Data Provider for ODBC as the destination driver.
Set the Connection String to your database in the following form:
Driver={PostgreSQL ODBC Driver(UNICODE)};Server=;Port=;Database=;UID=;PWD=
In the next page, you just need to select which tables you want to export. SQL Server will generate a default mapping and you are free to edit it. Probably you`ll encounter some Type Mismatch problems which take some time to solve. For example, if you have a boolean column in SQL Server you should export it as int4.
Microsoft Docs hosts a detailed description of connecting to PostgreSQL through ODBC.
PS: if you want to see your installed ODBC Driver, you need to check it via ODBC Data Source Administrator.
Take a look at the Software Catalogue. Under Administration/development tools I see DBConvert for MS SQL & PostgreSQL. Probably there are other similar tools listed.
You can use the MS DTS functionality (renamed to SSIS in the latest version I think). One issue with the DTS is that I've been unable to make it do a commit after each row when loading the data into pg. Which is fine if you only have a couple of 100k rows or so, but it's really very slow.
I usually end up writing a small script that dumps the data out of SQLServer in CSV format, and then use COPY WITH CSV on the PostgreSQL side.
Both those only take care of the data though. Taking care of the schema is a bit harder, since datatypes don't necessarily map straight over. But it can easily be scripted together with a static load of the schema. If the schema is simple (just varchar/int datatypes for example), that part can also easily be scripted off the data in INFORMATION_SCHEMA.
Well there are .NET bindings for MS SQL Server 2005 (obviously) and also for PostgreSQL. So it would only take a few lines of code to code up a program that could transfer data safely from one to the other. The view would probably have to be done manually as Postgres doesn't use the same language for views as SQL Server.
This answer is to help summarize current connection string because someone may overlooked the comment.
Current version of ODBC connection string is:
For 32-bit system
Driver={PostgreSQL UNICODE};Server=192.168.1.xxx;Port=5432;Database=yourDBname;Uid=postgres;Pwd=admin;
For 64-bit system
Driver={PostgreSQL UNICODE(x64)};Server=192.168.1.xxx;Port=5432;Database=yourDBname;Uid=postgres;Pwd=admin;
You can check the driver name by typing ODBC in windows search.
And open ODBC Data Source Administrator

Resources