Get the App
SLTechnology News&Howtos  ›  Database  › 

Mysql database basic command-simultaneous operation of multiple data

Shulou Source: shulou.com Published: 2022-06-01 08:41:47 10月03日 Update

Add primary key mysql > alter table info add primary key (id); Query OK, 0 rows affected (0.07 sec) Records: 0 Duplicates: 0 Warnings: 0mysql > desc info # View the primary key +-+-+ | Field | Type | Null | Key | Default | Extra | +- -+-+ | id | int (11) | NO | PRI | NULL | | # display the primary key | name | char (6) | YES | | NULL | | score | decimal (5Magin2) | YES | | NULL | | age | int (4) | YES | | NULL | | hobbly | int (4) | | | YES | | NULL | | +-+-+ 5 rows in set (0.00 sec) add foreign key alter table info add constraint FK_ID foreign key (hobbly) REFERENCES hy (id) | Mysql > show index from info\ G # check the foreign key * 2. Row * Table: info Non_unique: 1 Key_name: FK_ID # Foreign key added successfully Seq_in_index: 1 Column_name: hobbly Collation: a Cardinality: 3 Sub_part: NULL Packed: NULL Null: YES Index_type: BTREE Comment: Index_comment: 2 rows in set (0.00 sec) Table modifies a field (different list contents) update info set age=23,num=44 where id=2 at the same time Mysql > select * from info +-+-+ | id | name | score | hobbly | age | num | +-+-+ | 1 | zl | 88 | Reading | 33 | NULL | | 2 | Li Si | 68 | surfing the Internet | 23 | 44 | # modified successfully | 3 | Wang Si | 68 | watching TV | NULL | NULL | +-+ 3 rows in set (0.00 sec) simultaneously Add multiple fields mysql > alter table info add column age int Add column num int Query OK, 0 rows affected (0.05 sec) Records: 0 Duplicates: 0 Warnings: 0mysql > desc info # View table structure +-+ | Field | Type | Null | Key | Default | Extra | + -+ | id | int (11) | NO | PRI | NULL | name | char (4) | YES | | NULL | | score | char (6) | YES | | NULL | | hobbly | char (10) | YES | | NULL | | age | int (11) | YES | NULL | | num | int (11) | YES | | | | NULL | | +-+-+ delete multiple fields at the same time mysql > alter table info drop column age | Drop column num Query OK, 0 rows affected (0.05 sec) Records: 0 Duplicates: 0 Warnings: 0mysql > select * from info +-+ | id | name | score | hobbly | +-- + | 1 | zl | 88 | Reading | | 2 | Lisi | 68 | surfing the Internet | | 3 | Wang Si | 68 | watching electricity Depending on | +-+ delete multiple records at the same time (multiple lines) mysql > delete from info where id in (3pd4) Query OK, 2 rows affected (0.00 sec) mysql > select * from info +-1 | zl | 88 | Reading | 2 | Lisi | 68 | surfing the Internet | | 5 | kl | 88 | Swimming | + -+ view multiple specified records (rows) at the same time mysql > select * from info where id in (3pr 4) +-+ | id | name | score | hobbly | +-+ | 3 | Wang Si | 68 | watching TV | | 4 | ll | 67 | Reading | + -+

Tags: At the same time multiple field TV Li Si success multiple data different content structure table multi-row swimming command database Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Xiaomi Shulou Technology Shulou Tech Info NVidia