blog image

Database Basic commands

=>Command to insert table's data from one table to destination table

INSERT INTO destination_database_name.table_name (id,name,created_at,updated_at) SELECT id,name,created_at,updated_at FROM source_database_name;

#example
INSERT INTO production_school.category (id,name,created_at,updated_at) SELECT id,name,created_at,updated_at FROM testing_school.category;

 

=> command to set  existing value to new field in sql

UPDATE table_name
SET fieled_name_to_store_value  = existed_field_name_from_where_you_want_to_copy;


#example
UPDATE news 
SET created = created_at;

=> command to set  auto-increment value in sql

SET @sort_number := 0;

UPDATE table_name
SET filed_name_where_you_want_to_store = (SELECT @sort_number := @sort_number + 1)
ORDER BY some_ordering_column;


#example
SET @sort_number := 0;

UPDATE category
SET sort = (SELECT @sort_number := @sort_number + 1)
ORDER BY some_ordering_column;

=> 

DROP DATABASE my_database;
DROP TABLE my_table;


RENAME TABLE hu44m1la_terms TO category;

ALTER TABLE category CHANGE term_id id INT;

ALTER TABLE category DROP COLUMN term_group;

ALTER TABLE category
ADD created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
ADD updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;


ALTER TABLE category
ADD is_active BOOLEAN DEFAULT TRUE,
ADD category_color VARCHAR(255);

ALTER TABLE author DROP COLUMN user_pass;
ALTER TABLE author DROP COLUMN user_pass,user_nicename,user_login,user_activation_key,user_status,user_url,user_registered;

=> 

=> 

=> 

=> 

=> 

=> 

=> 

=> 

 


About author

author image

Amrit Panta

Python developer, content writer



3 Comments

Amanda Martines 5 days ago

Exercitation photo booth stumptown tote bag Banksy, elit small batch freegan sed. Craft beer elit seitan exercitation, photo booth et 8-bit kale chips proident chillwave deep v laborum. Aliquip veniam delectus, Marfa eiusmod Pinterest in do umami readymade swag. Selfies iPhone Kickstarter, drinking vinegar jean.

Reply

Baltej Singh 5 days ago

Drinking vinegar stumptown yr pop-up artisan sunt. Deep v cliche lomo biodiesel Neutra selfies. Shorts fixie consequat flexitarian four loko tempor duis single-origin coffee. Banksy, elit small.

Reply

Marie Johnson 5 days ago

Kickstarter seitan retro. Drinking vinegar stumptown yr pop-up artisan sunt. Deep v cliche lomo biodiesel Neutra selfies. Shorts fixie consequat flexitarian four loko tempor duis single-origin coffee. Banksy, elit small.

Reply

Leave a Reply

Scroll to Top