Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mysql database basic command-simultaneous operation of multiple data

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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 | + -+

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report