How can I create a copy of an Sybase table with data? - sap-ase

I know the statement in oracle which copies the structure and the data.
create table mytable1 as select * from mytable;
But how to achieve the same in Sybase ASE?

It is possible using select into!
Check more info HERE!

In Sybase ASE 16 the syntax for copying the data and structure is
SELECT field1, field2 INTO NewTable FROM OldTable
If you want to copy only the structure use this
SELECT field1, field2 INTO NewTable FROM OldTable WHERE 1=0

Related

Error with CTAS - Azure Synapse Analytics

I am trying to create a temp table in Synapse SQL using CTAS
IF OBJECT_ID('tempdb..#temp') IS NOT NULL DROP TABLE #temp
CREATE TABLE #temp
AS SELECT [State], LocalizedLabel FROM StateMetadata WHERE EntityName ='incident'
and getting an error message
Incorrect syntax near the keyword 'SELECT'.
Total execution time: 00:00:00.533
Error message snip
If I run SELECT statement by itself as highlighted it works
SELECT [State], LocalizedLabel FROM StateMetadata WHERE EntityName ='incident'
Select statement that works fine
and if I create temp table without using AS, it works fine as well
IF OBJECT_ID('tempdb..#temp') IS NOT NULL DROP TABLE #temp
CREATE TABLE #temp (
statecode int,
statecodename nvarchar(64)
)
SELECT * FROM #temp
Create temp table without using AS
I have tried brackets and everything I could. Not sure what I am possibly doing wrong. I am new to Synapse Analytics, Any help on this would be highly appreciated.
Thanks
Nidhi
CTAS requires a distribution option while creating. Include distribution options while creating temp tables using CTAS.
IF OBJECT_ID('tempdb..#temp') IS NOT NULL DROP TABLE #temp
CREATE TABLE #temp
WITH
(
DISTRIBUTION = ROUND_ROBIN
)
AS
SELECT StateName, StateCode FROM SP WHERE Region ='US';
select * from #temp

Postgres sql Insert overwrite mode

Is there any Insert overwrite mode in postgres sql like below.
INSERT OVERWRITE INTO TABLE table2 select * FROM table1;
PostgreSQL has the TRUNCATE command to wipe the contents of a table but keep the table itself. You would have to use two statements:
TRUNCATE table2;
INSERT INTO table2 SELECT * FROM table1;
If you want to INSERT new records and UPDATE existing records you can use the ON CONFLICT argument of the INSERT statement:
INSERT INTO table2 (id, name)
(SELECT id, name FROM table1)
ON CONFLICT (id_pkey) DO UPDATE SET name = EXCLUDED.name;
You need to have a primary key or UNIQUE constraint to perform the conflict check. Full details can be viewed in the INSERT Statement documentation, https://www.postgresql.org/docs/current/sql-insert.html
You can also choose to DO NOTHING on conflict which has the advantage of protecting against inserting duplicate records.

Is it possible to get insert statements from CQL column family?

I have columnfamily testtable with data. Can I somehow export data to INSERT statements?
desc testtable will give me code to create it, but how can I export data? thanks.
If you just want to export from one table to another you can use the CQL COPY command:
COPY keyspace.table1(column1, column2) TO 'temp.csv';
COPY keyspace.table2(column1, column2) FROM 'temp.csv';
This will copy all of the data from keyspace.table1 to keyspace.table2

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

how to truncate the data before insert using DTS

I have source server and destination server, i have insert the data from source to destination, but before that i have to delete the records if any in destination - (DTS)
If you want to remove whole existing table than create sql task and write :
drop table (tablename)
If you want to remove only data inside existing table than create sql task and write :
truncate table (tablename)
Create an Execute SQL task in the correct sequence of your package and call the following code to delete the rows
TRUNCATE TABLE tablename
Refer MSDN link for more details

Resources