24 Aralık 2020 Perşembe

ALTER TABLE

Giriş
Söz dizimi şöyle
ALTER TABLE table_name
ADD column_name data_type [constraint],
MODIFY column_name data_type [constraint],
DROP column_name,
ADD CONSTRAINT constraint_name constraint_definition,
DROP CONSTRAINT constraint_name;

DROP COLUMN
Örnek
Normalde şöyle yaparız
ALTER TABLE foo DROP COLUMN bar;
Ancak bazen "vsnprintf failed: Invalid argument" şeklinde bir hata geliyor. Bu durumda şöyle yaparız
SET lc_messsages = 'C';
ALTER TABLE
foo DROP COLUMN bar;
REPLICA IDENTITY
Örnek
Şöyle yaparız
ALTER TABLE ingredients REPLICA IDENTITY FULL;
Açıklaması şöyle
The ALTER TABLE command with the REPLICA IDENTITY clause is used to set the replication identity for a table. When using Debezium's PostgreSQL connector, the connector requires a unique primary key or a unique identifier to keep track of changes. If a table does not have a primary key or a unique identifier, you will get an error, saying that the table does not have a replica identity, which is used for tracking changes. By running ALTER TABLE ... REPLICA IDENTITY FULL, you're setting the table's replication identity to "full", which means that the entire row is used as the identifier for change tracking purposes.

Hiç yorum yok:

Yorum Gönder