After Alter Rename to with table, we cant create the table with old name - cockroachdb

Unable to create table with old name after using Alter Rename to (renamed table)
Alter table testdb rename to testdb2
now not able to create table with testdb
Cockroach Db Version: 19.1.2

Cockroach does not currently support atomically swapping table names. See this issue: https://github.com/cockroachdb/cockroach/issues/54562

I just tested this on v19.1.2 as well as several later versions, and it looks to be working fine:
> create table testdb (a int);
CREATE TABLE
> alter table testdb rename to testdb2;
RENAME TABLE
> create table testdb (a int);
CREATE TABLE
Can you share the commands you are running? There is a known limitation about this within the context of a single, multi-statement transaction, but I'm not clear if you're doing that: https://www.cockroachlabs.com/docs/stable/known-limitations.html#schema-changes-within-transactions
Also, v19.1.2 is quite old and is no longer supported. You should upgrade to at least 19.2: https://www.cockroachlabs.com/docs/releases/release-support-policy.html#current-supported-releases

Related

How to remove a strange table named "BIN$c+eOnMB3RbKSEfg/rsxtAQ==$0" from oracle database?

I am new to Oracle and for practice I have created some tables (customer, drivers, payment, booking, location, area, job, job_history) in Oracle 11g and upon select * from cat statement I have found a strange table with other created tables named "BIN$c+eOnMB3RbKSEfg/rsxtAQ==$0".I don't know why this table is created.
I tried to remove this table through
drop table BIN$c+eOnMB3RbKSEfg/rsxtAQ==$0;
but it gives error:
drop table BIN$c+*eOnMB3RbKSEfg/rsxtAQ==$0
ERROR at line 1: ORA-00933: SQL command not properly ended
what should I do to remove it?
What you see is a deleted table in the RECYCLEBIN
You may get the original name of the table with this query
SELECT original_name FROM RECYCLEBIN where OBJECT_NAME = 'BIN$c+eOnMB3RbKSEfg/rsxtAQ==$0';
Note that (with your parameter setting) if you DROP a table it is not completely removed, but moved in the recyclebin.
You may ommit this using the PURGE option.
DROP TABLE xxx PURGE;
To remove the table from the recyclebin you must qoute the name with double quotes (as this is not a valid name) and use the PURGE statement (not a DROP - which would trigger ORA-38301: can not perform DDL/DML over objects in Recycle Bin).
PURGE TABLE "BIN$c+eOnMB3RbKSEfg/rsxtAQ==$0"
Alternatively you may use the original_name obtained with the query above:
PURGE TABLE {your_original_name};
To clean up the recyclebin completely use this statement (with the propper table user)
PURGE RECYCLEBIN;

How to rename a hive table without changing location?

Based on the Hive doc below:
Rename Table
ALTER TABLE table_name RENAME TO new_table_name;
This statement lets you change the name of a table to a different name.
As of version 0.6, a rename on a managed table moves its HDFS location as well. (Older Hive versions just renamed the table in the metastore without moving the HDFS location.)
Is there any way to rename a table without changing the location?
Yeah we can do that. You just need to follow below three commands in sequence.
Lets say you have a external table test_1 in hive. And you want to rename it test_2 which should point test_2 location not test_1. Then you need to convert this table into Managed table using below command.
test_1 -> pointing to test_1 location
ALTER TABLE db_name.test_1 SET TBLPROPERTIES('EXTERNAL'='FALSE');
Rename the table name.
ALTER TABLE db_name.test_1 RENAME TO db_name.test_2;
Again convert the managed table after renaming to external table.
ALTER TABLE db_name.test_2 SET TBLPROPERTIES('EXTERNAL'='TRUE');
db_name.test_2 table will point the test_2 location. If we do it without making the managed table it will point the test_1 location.
As of Hive 2.2.0 a managed table's HDFS location is moved only if the table is created without a LOCATION clause and under its database directory.Link
ALTER TABLE does not follow the databasename.tablename syntax in Hive like it does in CREATE or SELECT.
Mention the databasename first and then run alter table statement.
syntax as below
USE databasename;
ALTER TABLE old_tablename RENAME TO new_tablename;
Here is the command executed
ALTER TABLE old_ratings RENAME TO ratings;

How to Recover an Entire Oracle Schema

I was using Navicat for Oracle to backup an entire Schema. I mistakenly selected the Execute SQL File instead of the Backup file option and All previous data has been changed/lost. I tried using the Oracle Undo feature but it says the table definition has changed. Please i am not skilled in oracle, i only used it for a project cause it was required so i just use it to store the data. I need all the help i can get right now to recover the entire schema to how it was 24 hours ago else i am so screwed...(forgive my language)
From your description you ran a script that dropped and recreated your tables. As you have flashback enabled and your dropped table is in the recycle bin, you can use the 'Flashback Drop' feature to get the dropped table back.
Here's an example with a single table:
create table t43 (id number);
drop table t43;
create table t43 (id2 number);
show recyclebin;
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
-------------------------------- ------------------------------ ------------------------- -------------------
T43 BIN$/ILKmnS4b+jgQwEAAH9jKA==$0 TABLE 2014-06-23:15:38:06
If you try to restore the table with the new one still there you get an error:
flashback table t43 to before drop;
SQL Error: ORA-38312: original name is used by an existing object
You can either rename the restored table:
flashback table t43 to before drop rename to t43_restored;
... which is useful if you want to keep your new table but be able to refer to the old one; or probably more usefully in your situation rename the new table before restoring:
alter table t43 rename to t43_new;
table T43 altered.
flashback table t43 to before drop;
table T43 succeeded.
desc t43
Name Null Type
---- ---- ------
ID NUMBER
You can undrop all of your tables, and as referential constraints still work with tables in the bin you don't have to worry too much about restoring parent tables before child tables, though it's probably neater to do that if you can.
Note that the bit in the documentation about retoring dependent objects - that index names won't be preserved and you'll need to rename them after the restore with alter index.
You can't undrop a sequence; those don't go into the recycle bin. If you need to reset a sequence so it doesn't repeat values you already have, you can get the highest value it should hold (from the primary keys on your restored table, say) and use temporarily change the increment value to skip over the used numbers.

How to convert a temporary table to permanent table in Oracle and vice versa

I would like to know which is the command to convert a temporary table to permanent table in Oracle.
Other issue is about the index. An index used in a temporary table will be the same used in a permanent table, if I convert it?
You can't convert a table from a temporary table to a permanent table.
You can create a new permanent table that matches the structure of the temporary table
CREATE TABLE new_permanent_table
AS
SELECT *
FROM old_temporary_table
WHERE 1=0;
Or you could get the DDL for the temporary table using the DBMS_METADATA package and manually edit the DDL to create the new permanent table.
Then you can create whatever indexes you would like on the new permanent table and drop the old temporary table. Once the old temporary table is dropped, you can rename the permanent table to use the name of the old temporary table if you would like.

Oracle Database creation with exitsting tables

I've database with 15 tables. Now due to development process one column has to added to all the tables in the database. This changes should not affect the existing process because some other services are also consuming this database. So to accomplish it I thought of creating a new database. Is there are any other way to do it.
Usually it should be enough to create a new schema ("user") and create the tables in that new schema. In Oracle, identically named tables can exist in several schemas.
CREATE USER xxx IDENTIFIED BY yyy
you can create another schema for development and import the table to new schema.Developer should use the development schema instead of production schema.you can also create new database and import from current database but it might be last option
What's wrong with alter table T add (COL varchar2(5)); ?
Of course dependend stored procedures or packages become invalid.
You can leave them alone, then the first call would return an exception and auto-recompile the called procedure. Or you can alter procedure P compile;.

Resources