PostgreSQL – SQL commands

List of some useful MySQL commands in SQL queries.

Resetting the increment:

ALTER TABLE market AUTO_INCREMENT = 1;
ALTER TABLE outcome AUTO_INCREMENT = 1;

Add a new column (one command at a time):

ALTER TABLE table_name ADD post_date_gmt datetime NOT NULL DEFAULT ‘0000-00-00 00:00:00’
ALTER TABLE table_name ADD post_title text COLLATE utf8mb4_unicode_ci NOT NULL
ALTER TABLE table_name ADD post_content longtext COLLATE utf8mb4_unicode_ci NOT NULL
ALTER TABLE table_name ADD post_author bigint (20) unsigned NOT NULL DEFAULT ‘0’

Rename Column:

ALTER TABLE table_name CHANGE post_date_gmt date_creation_gmt datetime NOT NULL DEFAULT ‘0000-00-00 00:00:00’;
ALTER TABLE table_name CHANGE post_title title text COLLATE utf8mb4_unicode_ci NOT NULL;
ALTER TABLE table_name CHANGE post_content content longtext COLLATE utf8mb4_unicode_ci NOT NULL;
ALTER TABLE table_name CHANGE post_author author_id bigint (20) unsigned NOT NULL DEFAULT ‘0’;

Update specific values ​​in a column:

UPDATE table_name SET category = REPLACE (category, ‘work’, ‘2’);

Update all values ​​in a column:

UPDATE table_name SET category = 1;

Update empty data in the column with some other data, for example, number 1:

UPDATE table_name set category ="one" where category is null OR category =""

UPDATE table_name set user_id ="one"

Or

AND (t.status = “a” OR t.status = “b”)

Delete column:

ALTER TABLE actions DROP COLUMN name_ru;

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *