Learn Python

Learn Data Structure & Algorithm

Learn Numpy

Learn Pandas

Learn Matplotlib

Learn Seaborn

Learn Statistics

Learn Math

Learn MATLAB

Learn Machine learning

Learn Github

Learn OpenCV

Learn Deep Learning

MySQL Introduction

MySQL Setup

MySQL Operators

MySQL Basic Works

MySQL Create Table

MySQL insert and get values

MySQL Condition

MySQL GROUP BY

MySQL Case

MySQL sorting and calculate avg,sum,count

MySQL Update

MySQL Time

MySQL String

MySQL Rollback & Commit

MySQL Join and Concatenate

MySQL Index

MySQL Date

MySQL View

MYSQL With Python

Learn MongoDB

Learn Web scraping

Learn Excel

Learn Power BI

Learn Tableau

Learn Docker

Learn Hadoop

All you need to know to update sql table or database using SQL

How to add column in table?

Syntax:
ALTER TABLE table_name
ADD column_name dataType;

Let's see example:
Suppose you have a database named STD and there you have a table named student. Inside the table you have columns like id, name, percentage,dob, age, gender, city, courses.

ALTER TABLE student
ADD grade varchar(255);

How to change data type of a column?

Syntax:
ALTER TABLE table_name
MODIFY column_name datatype;

Let's see example:
Suppose you have a database named STD and there you have a table named student. Inside the table you have columns like id, name, percentage,dob, age, gender, city, courses.

ALTER TABLE student
MODIFY grade INT(10);

How to update value of a table?

Syntax:
update table_name set column_name=value where condition;

Example:
update books_store_1 set price=400 where books="Python"; What we did here, we set the price 400 of the python book.

How to change or add constant of a column?

Syntax:
ALTER TABLE table_name
ADD constant_name (column_name);

Let's see example:
Suppose you have a database named STD and there you have a table named student. Inside the table you have columns like id, name, percentage, dob, age, gender, city, courses.

ALTER TABLE student
ADD UNIQUE (name);

How to change column name?

Syntax:
ALTER TABLE table_name
CHANGE column_name new_column_name datatype;

Let's see example:
Suppose you have a database named STD and there you have a table named student. Inside the table you have columns like id, name, percentage, dob, age, gender, city, courses.

ALTER TABLE student
CHANGE name Name_of_student varchar(255);

How to change column position?

Syntax:
ALTER TABLE table_name
MODIFY column_name
AFTER that_column_name_after_which_you_want_to_see;

Let's see example:
Suppose you have a database named STD and there you have a table named student. Inside the table you have columns like id, name, percentage, dob, age, gender, city, courses.

ALTER TABLE student
ADD grade varchar(255)
AFTER percentage;

How to delete a column?

Syntax:
ALTER TABLE table_name
DROP COLUMN column_name datatype;

Let's see example:
Suppose you have a database named STD and there you have a table named student. Inside the table you have columns like id, name, percentage, dob, age, gender, city, courses.

ALTER TABLE student
DROP COLUMN Name_of_student;

How to rename table?

Syntax:
ALTER TABLE table_name
RENAME new_table_name;

Let's see example:
Suppose you have a database named STD and there you have a table named student. Inside the table you have columns like id, name, percentage, dob, age, gender, city, courses.

ALTER TABLE student
RENAME Students_info;

How to add a column to an existing table?

Syntax:
ALTER TABLE table_name
ADD column_name datatype NOT NULL UNIQUE...etc constraint;

Example:
ALTER TABLE my_table
ADD Email varchar(255) NOT NULL;

How to delete a column from an existing table?

Syntax:
ALTER TABLE first_table
DROP COLUMN Email;

Example:
ALTER TABLE first_table
DROP COLUMN Email;

How to drop a table?

Syntax:
DROP TABLE Table_name;

Example:
DROP TABLE My_second_table;

How to drop or delete all the values present in a table?

Syntax:
DROP TABLE Table_name;

Example:
TRUNCATE TABLE My_second_table;

How to delete value of a column?

Syntax:
delete from table_name where condition;

Example:
delete from books_store_1 where price < 150;

What we did here, we delete those values which contain less than 150 in the price column.

CodersAim is created for learning and training a self learner to become a professional from beginner. While using CodersAim, you agree to have read and accepted our terms of use, privacy policy, Contact Us

© Copyright All rights reserved www.CodersAim.com. Developed by CodersAim.