How to create primary key with disable status using liquibase changeset?
I want to create partitioned index of primary key with storage parameters like init trans and max trans using liquibase changeset.
so first, I used to create primary key on column, then disable primarykey which drop unique index, than create partitioned index on primary key and than enable primarykey.
How to achieve in liquibase?
The only way to do this in Liquibase currently would be using the <sql> or <sqlFile> change types.
Related
How to drop composite key in liquibase using SQL commands ? My composite key doesn't have a name for it.
I tried searching liquibase documentation but it says about primary keys only.
A composite key is a primary key. So if you found a way to drop a primary key, then use it.
As you want to use SQL command, not Liquibase XML, JSON etc., then this is a question how to drop a composite key in SQL. An answer depends on a database engine you use. For example in MySQL, you can do that like this:
ALTER TABLE CITIES DROP PRIMARY KEY;
A primary key from the CITIES table will be deleted even if it is a composite key.
To make it runnable from Liquibase, you just add a comment line with Liquibase meta data. For example:
--changeset Harsh:1
ALTER TABLE CITIES DROP PRIMARY KEY;
Using Hue, how can I alter a table to make a prexisting column a primary key?
I check and things like :
ALTER TABLE table_name ADD CONSTRAINT colname PRIMARY KEY (cs_id);
is not syntactically correct.
NB: data is stored using Kudu file system.
First, Impala does not support alter contraint as an option in alter table.
Second, primary keys are very limited:
The primary key columns must be the first ones specified in the CREATE TABLE statement.
I don't think you can change the primary key after it has been defined. In Impala, the data is clustered (i.e. sorted) by the primary key, so any change would be quite expensive.
You probably need to recreate the table and reload it with data.
When you are storing as Kudu, you need to consider that the PK columns need to be all created at the creation of the table.
Impala does not support altering primary keys.
I'm afraid you need to delete and create the table again.
I can create a primary key specifying its name with some thing like this:
ALTER TABLE MY_TABLE ADD CONSTRAINT MY_TABLE_PK PRIMARY KEY (ID);
The engine also creates a unique index named something like SYS_IDX_11905.
I don't know of a way to specify its name at creation and if I try to rename it with
ALTER INDEX SYS_IDX_11905 RENAME TO MY_TABLE_ID_UINDEX
I get java.lang.RuntimeException: org.hsqldb.HsqlException: user lacks privilege or object not found: SYS_IDX_11905.
Is there any way in which I can specify the name of the index?
The user cannot drop or rename the automatically created indexes. See also http://hsqldb.org/doc/guide/dbproperties-chapt.html#dpc_sql_conformance for the sql.sys_index_names property, which can be set to use the same name for the index as the primary key constraint.
I am trying to replicate a table using CTAS clause in redshift by additionally specifying a primary key to the table.
Tried below syntax but no luck. However, I was able to specify DISTKEY/SORTKEY using the same syntax
create table date_dim
PRIMARY KEY(date_key)
--DISTKEY ( date_key )
as
select date_key,
calendar_date,.....;
I want to use primary key as part of merge logic I am designing in my flow.
TIA!
Many people consider primary and foreign keys in Redshift to be an anti-pattern (because they're unenforced), but my team built a small tool (a Python script) that supports this scenario.
You write your select statement in a normal SQL file, define primary key, foreign keys, distkey, etc in a YAML configuration file, and then use the script to generate (and optionally execute) SQL to create and populate the table.
We also include an Airflow operator to make it simple to schedule and automate this.
The repo is here, and we wrote a bit more about it on our team blog
You can only specify distkey and sortkey in CTAS . Here is the below link which describes what all options you can specify
Redshift CTAS
If the column you are wishing to dub as primary key is already non-nullable you can use this:
ALTER TABLE <table_name> ADD CONSTRAINT <a_name_for_this_constraint> PRIMARY KEY (<attribute_name>)
e.g.: ALTER TABLE member ADD CONSTRAINT pk_1 PRIMARY KEY (member_id);
Redshift doesn't support primary and foreign key constraints: http://docs.aws.amazon.com/redshift/latest/dg/t_Defining_constraints.html
Can we drop and recreate a composite primary key in a SQL Server table in production environment? Do we have take down the server for it, or can we do it live?
Because we have to add more columns to the primary key. If we done it in live what are the problems we have to face?
You can remove primary key from table.This will also remove clustered index of that table if you have't mentioned explicitly on other column.
To remove primary key run below query
-- Drop CHECK CONSTRAINT from the table
ALTER TABLE /*schema*/./*table*/
DROP CONSTRAINT /*constraint_name*/
GO
and to add primary key run below code
-- Add a new CHECK CONSTRAINT to the table
ALTER TABLE /*schema*/./*table*/
ADD CONSTRAINT /*contraint_name*/ /*constraint_type*/ (/*constraint_column_name*/ /*logical_expression*/)
GO