How To: Alter Table In MySQL (3 Min) | Modify Columns, Alter Foreign Key Contraints

Опубликовано: 04 Февраль 2022
на канале: Gokce DB
364
4

In this tutorial, you'll learn how to alter table in MySQL, modify table columns, delete columns, alter foreign keys and more.


Facebook:   / gokcedbsql  

Video Transcript:

Connect MySQL In Python:    • How To Connect To MySQL In Python (2 ...  

Hi guys, this is Abhi from Gokcedb. In this video, you're going to learn how to use Alter Table in MySQL. Let’s start by creating these four tables' properties.

Cache underscore sales, sales underscore status, and customer. Let's look at the create table SQL for the property table. Here, I'm using ID as my primary key to connect to the MySQL Database.

I'm using a config file to pass in my authentication details. Next, let's input create table property SQL file to the MySQL alias. To check the table structure, use the desc or the describe keyword.

I'm going to speed up the video and create the rest of the tables. Let’s say I want to alter the cash underscore sales table and modify the cash underscore sales underscore doc underscore fee column and change the data type to decimal 13 comma 2 and remove the not null constraint. To do that, I'm going to write alter table cash underscore sales modify cash underscore sales underscore doc underscore fee decimal 13 commas 2 in parentheses.

To verify if the changes went through, use the describe or the desc keyword. Say you wanted to get rid of the doc fee column altogether that you would write alter table cash underscore sales drop column cash underscore sales underscore dock underscore fee. Use the described keyword to verify.

To add the column back, type alter table cash underscore sales add column cash underscore sales underscore dock underscore fee decimal 10 commas 2 not null after cash underscore sales underscore price. Use the describe keyword to verify. Say you wanted to get information on the foreign key constraints on the cash underscore sales table.

To do that, type show create table cash underscore sales. Next, if you wanted to get rid of the FK underscore cash underscore sales underscore property underscore id foreign key. Here's how you do it.

Type alter table cash underscore sales drop foreign key then the name of the foreign key. To verify, use the show create table keyword. To add to the table you would type alter table, cache underscore sales at constraint name of the constraint, name of the constraint foreign key, property underscore ID, references, property id on delete cascade on update cascade.

To verify your changes, use the show create table keyword. There you have it. Make you like, subscribe and turn on the notification bell. Until next time.


Смотрите видео How To: Alter Table In MySQL (3 Min) | Modify Columns, Alter Foreign Key Contraints онлайн, длительностью часов минут секунд в хорошем качестве, которое загружено на канал Gokce DB 04 Февраль 2022. Делитесь ссылкой на видео в социальных сетях, чтобы ваши подписчики и друзья так же посмотрели это видео. Данный видеоклип посмотрели 364 раз и оно понравилось 4 посетителям.