Can we create TABLE datatype in Sybase? - sap-ase

As we have in SQL Server, is it possible to create a TABLE datatype in Sybase? I checked a couple of online forums but was not able to find any answer.

TABLE is a T-SQL reserved word, so is not usable as the name of a datatype.
The full list of reserved words can be found in the Sybase ASE Quick Reference Guide

I had a similar question recently. The table data type does exist in T-SQL as illustrated by MSDN library https://msdn.microsoft.com/en-us/library/ms175010.aspx. HOWEVER, It is NOT SUPPPORTED in Sybase. In T-SQL the table data type can be declared AS
DECLARE #tableVariable table(Column1 int, Column2 int)
I had intended on using the table variable to store a result set for use later to be UNION'd for each value in an array, but I was disappointed to find out that Sybase ASE DOES NOT support the table data type variable. A list of supported data types can be found here

To create a temporary table in Sybase you will use the code:
CREATE TABLE #table (Column1 int, Column2 int)
Example of select:
SELECT * FROM #table
The table exists until the current session or procedure ends, or until its owner drops it using drop table.

Related

How to specify data type while writing a Unique constraint using sql alchemy

I have some python code that I am refactoring, I can see that the tables have a column called "my_column" with a data type integer. Does this automatically get created?
Also is there a way I can explicitly set the data type of "my_column" to BigInt?
A UniqueConstraint is separate from the table columns and doesn't have a data type. In your example there should be a separate Column() named "my_column".
The unique constraint is only created when doing something like Base.metadata.create_all(engine) or via a migration using something like alembic.
To alter an existing table you could use something like alembic to create a migration that would only be run once to change a column's datatype.

Not able to alter cassandra db from bigint to text

I have column toor_0_sup with the bigint in cassandra db I want to change datatype to text.
How I can do that??
As we know for cassandra we cant change datatype from bigint to text.
If any solution for that will help me.
Tried to alter table but not working.
By this thread discussion Altering column types is no longer supported.
REF: https://dba.stackexchange.com/questions/314933/how-do-we-handle-alter-table-column-type-in-cassandra-in-actual-scenarios
Possible approach:
unload the table data
drop the table
create the table with structure
load the data

alter external table in sql azure

I am trying to alter external table column name to new name
I followed this post
ALTER EXTERNAL TABLE RemoteCustomerTable RENAME [OldName] column TO [Name]
Error:
Incorrect syntax near the keyword 'TABLE'.
Can external table be altered ?
Any help would be great.
Update:
As i dont see any official docs to alter external table, so i droped the external table and re-created it using this post
DROP EXTERNAL TABLE RemoteCustomerTable;
Alter external table is not a supported operation in Azure SQL Database. As you pointed out, DROP and then CREATE is the way to go.

Sybase ASE 15.5 Identity columns

I have created couple of tables using the Sybase Central tool in Sybase ASE 15.5 (Sybase AnyWhere). I have defined a column as a primary key (int data type) and somehow the column has become Identity as well.
Now from Sybase Central, there is no way I can remove the Identity from that column, even if there is no data in this table or in any of the referenced tables.
Can anybody help? I don't want to use Set IDENTITY_INSERT, I want to remove the identity behavior altogether from this column.
Thanks
Your question is a little confusing, as I'm not sure what Sybase software, or software version you are using. Sybase ASE 15.5 is not the same as Sybase SQL Anywhere, but hopefully these steps will work regardless.
You can not remove the identity behavior from a column, but you can alter the table to accomplish the same thing. Here are the steps you should take to preserve your data. Ensure there are no indexes on the table.
Alter the table to add a new column with the same datatype as the current identity column.
Copy the data from the identity column to the new column.
Drop the identity column
(Optional)If you've written any code against the table, you will probably want to rename the new column to the same name as the column that was just dropped.
alter table TABLE_NAME add NEW_COL int NULL
go
update TABLE_NAME set NEW_COL = ID_COL_NAME
go
alter table TABLE_NAME drop ID_COL_NAME
go
alter table TABLE_NAME rename NEW_COL to ID_COL_NAME
go

Adding columns to a sybase table with unique auto_identity index option

I've inherited a Sybase database that has the 'unique auto_identity index' option enabled on it. As part of an upgrade process I need to add a few extra columns to the tables in this database i.e.
alter table mytable add <newcol> float default -1 not null
When I try to do this I get the follow error:
Column names in each table must be unique, column name SYB_IDENTITY_COL in table #syb__altab....... is specifed more than once
Is it possible to add columns to a table with this property enabled?
Update 1:
I created the following test that replicates the problem:
use master
sp_dboption 'esmdb', 'unique auto_identity indexoption',true
use esmdb
create table test_unique_ids (test_col char)
alter table test_unique_ids add new_col float default -1 not null
The alter table command here produces the error. (Have tried this on ASE 15/Solaris and 15.5/Windows)
Update 2:
This is a bug in the Sybase dbisql interface, which the client tools Sybase Central and Interactive SQL use to access the database and it only appears to affect tables with the 'unique auto_identity index' option enabled.
To work around the problem use a different SQL client (via JDBC for example) to connect to the database or use isql on the command line.
Should be no problem to ALTER TABLE with such columns; the err msg indicates the problem regards something else. I need to see the CREATE TABLE DDL.
Even if we can't ALTER TABLE, which we will try first, there are several work-arounds.
Responses
Hah! Internal Sybase error. Open a TechSupport case.
Workaround:
Make sure you get jthe the exact DDL. sp_help . Note the IDENTITY columns and indices.
Create a staging table, exactly the same. Use the DDL from (1). Exclude the Indices.
INSERT new_table SELECT old_table. If the table is large, break it into batches of 1000 rows per batch.
Now create the Indices.
If the table is very large, AND time is an issue, then use bcp. You need to research that first, I am happy to answer questions afterwards.
When I ran your sample code I first get the error:
The 'select into' database option is not enabled for database 'mydb'. ALTER TABLE with data copy cannot be done. Set the 'select into' database option and re-run
This is no doubt because the data within your table needs copying out because the new column is not null. This will use tempdb I think, and the error message you've posted refers to a temp table. Is it possible that this dboption has been accidentally enabled for the tempdb?
It's a bit of a shot in the dark, as I only have 12.5 to test on here, and it works for me. Or it could be a bug.

Resources