Get the App
SLTechnology News&Howtos  ›  Database  › 

The method of adding Fields in mysql

Shulou Source: shulou.com Published: 2022-06-01 18:58:20 09月20日 Update

This article mainly gives you a brief introduction to the method of adding fields to mysql. You can look up the relevant professional terms on the Internet or find some related books to supplement them. We will not dabble here, so let's go straight to the topic. I hope this article on the method of adding fields in mysql can bring you some practical help.

How does mysql add fields?

Mysql adds two fields:

Mysql > create table id_name (id int,name varchar (20)); Query OK, 0 rows affected (0.13 sec) mysql > alter table id_name add age int,add address varchar (11); Query OK, 0 rows affected (0.13 sec) Records: 0 Duplicates: 0 Warnings: 0mysql > desc id_name +-+ | Field | Type | Null | Key | Default | Extra | +-+- -+ | id | int (11) | YES | | NULL | | name | varchar (20) | YES | | NULL | | age | int (11) | YES | | NULL | | address | varchar (11) | YES | | NULL | | + -+ 4 rows in set (0.00 sec)

Add a field to mysql:

Alter table user add COLUMN new1 VARCHAR (20) DEFAULT NULL; / / add a field, default is empty alter table user add COLUMN new2 VARCHAR (20) NOT NULL; / / add a field, default cannot be empty

Here's how to add fields to mysql. If you want to know about other related issues, you can continue to pay attention to our industry information. Our section will capture some industry news and professional knowledge to share with you every day.

Tags: Fields methods specialties industries expertise two topics books content practice news terminology sections knowledge articles information questions Tiandu help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Xiaomi OPPO Reno Huawei Microsoft