ignite DBMS, how rename column - ignite

we have the ignite DBMS, the task is to rename the column, as far as I was able to find information ignite does not support renaming, what do you advise? I had an idea to add a new column, move the values from the old column to it after delete the old column, but the old column is included in the primaty key, I also could not find the information how to add the primaty key in ignite.
To make it clearer, have is a table with columns column1, column2, column3, column4 where column1, column2 is the primary key, you need column2 to be called column_2

You essentially can't change the primary key columns in Ignite in an existing table. You could create a new table, move the data there, and drop the old one.

Related

Generate and Insert surrogate keys into already existing BigQuery table

I have an existing table without any unique ID. I'm planning to generate surrogate keys using GENERATE_UUID() statement however I'm sure not how to insert this new column... What is the best option here?
One way is to use CREATE OR REPLACE TABLE ... AS SELECT
CREATE OR REPLACE TABLE table_a
AS SELECT GENERATE_UUID() uuid, * FROM table_a
The drawback is:
The metadata of the table is lost (table options, column descriptions etc.)
Nullability of the columns is lost, all columns becomes NULLABLE
If both are acceptable, then approach above is the simplest way
If not, then you need to add a column through UI or API, then do
UPDATE table_a
SET uuid = GENERATE_UUID()
WHERE uuid IS NULL

Contraints for unique row insertion in Hive

I am creating a hive table with a large data set, Is there way of creating constraints on the table so that no two rows are the same when we insert the data.
Hive does not provide validated UNIQUE, PRIMARY KEY constraints.
As of 2.1.0 Hive includes support for non-validated primary and foreign key constraints. Since these constraints are not validated, an upstream system needs to ensure data integrity before it is loaded into Hive. And as of 3.0.0 Hive includes support for UNIQUE, NOT NULL, DEFAULT and CHECK constraints. Beside UNIQUE all three type of constraints are enforced.
You can apply DISTINCT or ROW_NUMBER, to all the dataset or partition. Also you can use UNION old data with new data for simply removing duplicates. If your table is partitioned, you can rewrite partition in such way:
insert overwrite table MYTABLE partition(load_date='2020-07-25')
select col1, col2, ... colN
from MYTABLE where load_date='2020-07-25'
UNION
select col1, col2, ... colN
from DAILY_INCREMENT_DATA
UNION will return distinct rows.
See also this answer for more details about using row_number and other loading scenarios.
Also Hive 2.2 supports MERGE in ACID mode.

Bulk Insert Only New Rows

I have a a group of csv files that I'm using to populate a SQL database. I'm setting this up to be a daily process. I've just discovered though that a handful of the files come in each day with all the historical data, not just the daily updates.
When I try to do the bulk insert this causes an error because the primary key is being violated.
I thought that setting IGNORE_DUP_KEY = ON would stop the non-unique records from being inserted.
CREATE TABLE TABLE1
(
Column1 varchar(32),
Column2 varchar(32),
Column3 char(9),
Column4 int,
Column5 float(53),
Column6 date,
CONSTRAINT pk_One
PRIMARY KEY (Column1, Column2, Column6)
WITH (IGNORE_DUP_KEY = ON)
);
Then when I try to run the script that updates the tables I get the unhelpful error message "Associated statement is not prepared (0)."
I could get around this by writing the results into a separate table, then writing the new rows into the table proper, but having separate handling for the different tables strikes me as painful, and ugly.
Is there an easy way to just tell SQL to only write the rows that don't violate the primary key constraint?
Insert into table1 (column1) value (value1)
... So, if you just want to ignore inserts that fail, do INSERT IGNORE INTO. Then it'll try to insert the values, fail, and move on gracefully. If you want it to replace the duplicate key values with the new values it attempted to insert, check out : (below, ignore optional, depends on if you want it to throw errors.)
INSERT [IGNORE] INTO table1 (column1) values (value1) ON DUPLICATE KEY UPDATE
so "insert ignore" is the answer, on inserts not on table creation. refer to mysql docs. and ON DUPLICATE KEY UPDATE is useful to know.

Unique index in already existing database table

I am trying to add a new unique index on one of my database tables in SQL Server 2008. This is an existing table and the column where I want the unique index already has some duplicate values.
Can I set up a unique index for that column? If so, how?
You can't set this column up with a UNIQUE index if the table already has duplicate values, unless you remove the records containing the duplicate values for that column. This goes to the definition of UNIQUE.
First you are gonna need to delete the duplicate values on your column and then you can create a unique index on it. So lets assume your table has 2 columns, id and column1. To delete duplicate values you need to choose one, it can be random or with some order. So it would be like this:
WITH CTE AS
(
SELECT *, ROW_NUMBER() OVER(PARTITION BY column1 ORDER BY Id) Corr
FROM YourTable
)
DELETE FROM CTE
WHERE Corr > 1
CREATE UNIQUE INDEX I_Unique ON YourTable(Column1)
No as the name suggest, Unique Index which says key has to be unique. So you cant
See this
If the column already has duplicate values then I would recommend you create a unique composite key instead.
e.g.
So, to handle that issue with this table design, you need to create a unique constraint on the table CustomerID/ProductID columns:
create unique index cust_products_unique on CustomerProducts (CustomerID, ProductID)
So that in essence a combination of fields ensures that the index is unique.
Regards
May not have been true in SQL Server 2008, however you can use Management Studio to do this in later versions such as 2014.
Right click your table
Choose Design
Expand "Identity Specification" and set (is Identity) to Yes
Save

How to insert duplicate rows in SQLite with a unique ID?

This seems simple enough: I want to duplicate a row in a SQLite table:
INSERT INTO table SELECT * FROM table WHERE rowId=5;
If there were no explicit unique column declarations, the statement would work, but the table's first column is declared rowID INTEGER NOT NULL PRIMARY KEY. Is there any way to create a simple statement like the one above that works without knowing the schema of the table (aside from the first column)?
This can be done using * syntax without having to know the schema of the table (other than the name of the primary key). The trick is to create a temporary table using the "CREATE TABLE AS" syntax.
In this example I assume that there is an existing, populated, table called "src" with an INTEGER PRIMARY KEY called "id", as well as several other columns. To duplicate the rows of "src", use the following SQL in SQLite3:
CREATE TEMPORARY TABLE tmp AS SELECT * FROM src;
UPDATE tmp SET id = NULL;
INSERT INTO src SELECT * FROM tmp;
DROP TABLE tmp;
The above example duplicates all rows of the table "src". To only duplicate a desired row, simply add a WHERE clause to the first line. This example works because the table "tmp" has no primary key constraint, but "src" does. Inserting NULL primary keys into src causes them to be given auto-generated values.
From the sqlite documentation: http://www.sqlite.org/lang_createtable.html
A "CREATE TABLE ... AS SELECT" statement creates and populates a database table based on the results of a SELECT statement. A table created using CREATE TABLE AS has no PRIMARY KEY and no constraints of any kind.
If you want to get really fancy, you can add a trigger that updates a third table which maps old primary keys to newly generated primary keys.
No. You need to know the schema of the table to write the insert statement properly.
You need to be able to write the statement in the form of:
insert into Table (column1, column2, column3)
select column1, column2, column3
from OtherTable
where rowId = 5
Well, since I was unable to do this the way I wanted, I resorted to using the implicit row id, which handily enough has the same name as the rowId column I defined explicitly, so now I can use the query I had in the question, and it will insert all the data with a new rowId. To keep the rest of the program working, I just changed SELECT * FROM table to SELECT rowId,* FROM table and everything's fine.
Absolutely no way to do this. Primary Key declaration implies this field is unique. You can't have a non unique PK. There is no way to create a row with existing PK in the same table.