search
HomeDatabaseMysql TutorialMySQL中数据表的增操作_MySQL

今天学习到表的增操作,写个博客总结一下,PS:下面所有的注释都是我在电脑上全部操作完成后,再复制到记事本上添加的。至于在执行的时候可不可以那样添加注释,就有待考证了。

选择库

mysql> show databases;#查看目前有哪些数据库存在+--------------------+| Database           |+--------------------+| information_schema || ceshi_ku           || mysql              || performance_schema |+--------------------+4 rows in set (0.00 sec)mysql> use ceshi_ku;#选择该数据库,等下用来建表,貌似选择数据库可以不要";"Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changed

建表

mysql> create table biao    -> (    -> id int,    -> name char(10),    -> gender char(2),    -> gongsi char(15),    -> gongzi float    -> );#先建立一个简单的表,编号、名字、性别、公司、工资,建表目前不是重点,是方便接下来的操作Query OK, 0 rows affected (0.13 sec)mysql> select * from biao;#查看表中的内容,目前是空表Empty set (0.00 sec)

插入数据(全部列,多行)

mysql> insert into biao#选择要插入哪张表    -> (id,name,gender,gongsi,gongzi)#往哪些列里面插入内容    -> values#接下来开始插入3条,分别用","隔开,最后一个用";"    -> (1,'ma yun','n','tao bao',6000.5),#把要插入内容依次写好,不可调换顺序!要一一对应    -> (2,'xiao hong','v','xin lang',5000.7),    -> (3,'xiao ming','n','bai du',3000.4);Query OK, 3 rows affected (0.08 sec)Records: 3  Duplicates: 0  Warnings: 0mysql> select * from biao;#查看表中的内容,现在会发现多了3行+------+-----------+--------+----------+--------+| id   | name      | gender | gongsi   | gongzi |+------+-----------+--------+----------+--------+|    1 | ma yun    | n      | tao bao  | 6000.5 ||    2 | xiao hong | v      | xin lang | 5000.7 ||    3 | xiao ming | n      | bai du   | 3000.4 |+------+-----------+--------+----------+--------+3 rows in set (0.01 sec)

插入数据(缺省列,单行)

mysql> insert into biao#这次没有指定往哪些列里面插入,没指定就是往所有列插入    -> values    -> (4,'li si','n','sou hu',9000.2);#这次是只插入一行,也可以插入多行,只需用","隔开Query OK, 1 row affected (0.07 sec)mysql> select * from biao;#查看表内容,会发现比上次多了一行+------+-----------+--------+----------+--------+| id   | name      | gender | gongsi   | gongzi |+------+-----------+--------+----------+--------+|    1 | ma yun    | n      | tao bao  | 6000.5 ||    2 | xiao hong | v      | xin lang | 5000.7 ||    3 | xiao ming | n      | bai du   | 3000.4 ||    4 | li si     | n      | sou hu   | 9000.2 |+------+-----------+--------+----------+--------+4 rows in set (0.00 sec)

插入数据(指定列,多行)

mysql> insert into biao    -> (id,name,gongsi,gongzi)#这次不是往所有列插入,而是部分列    -> values    -> (5,'lao wang','wang yi',1000.5),#依次写好便可,记得对应关系,    -> (6,'xiao li','ku gou',700.1);Query OK, 2 rows affected (0.15 sec)Records: 2  Duplicates: 0  Warnings: 0mysql> select * from biao;#查看表内容,这次会上次发现多了2行,但是"gender"是空的+------+-----------+--------+----------+--------+| id   | name      | gender | gongsi   | gongzi |+------+-----------+--------+----------+--------+|    1 | ma yun    | n      | tao bao  | 6000.5 ||    2 | xiao hong | v      | xin lang | 5000.7 ||    3 | xiao ming | n      | bai du   | 3000.4 ||    4 | li si     | n      | sou hu   | 9000.2 ||    5 | lao wang  | NULL   | wang yi  | 1000.5 ||    6 | xiao li   | NULL   | ku gou   |  700.1 |+------+-----------+--------+----------+--------+6 rows in set (0.00 sec)
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How Do I Drop or Modify an Existing View in MySQL?How Do I Drop or Modify an Existing View in MySQL?May 16, 2025 am 12:11 AM

TodropaviewinMySQL,use"DROPVIEWIFEXISTSview_name;"andtomodifyaview,use"CREATEORREPLACEVIEWview_nameASSELECT...".Whendroppingaview,considerdependenciesanduse"SHOWCREATEVIEWview_name;"tounderstanditsstructure.Whenmodifying

MySQL Views: Which design patterns can I use with it?MySQL Views: Which design patterns can I use with it?May 16, 2025 am 12:10 AM

MySQLViewscaneffectivelyutilizedesignpatternslikeAdapter,Decorator,Factory,andObserver.1)AdapterPatternadaptsdatafromdifferenttablesintoaunifiedview.2)DecoratorPatternenhancesdatawithcalculatedfields.3)FactoryPatterncreatesviewsthatproducedifferentda

What Are the Advantages of Using Views in MySQL?What Are the Advantages of Using Views in MySQL?May 16, 2025 am 12:09 AM

ViewsinMySQLarebeneficialforsimplifyingcomplexqueries,enhancingsecurity,ensuringdataconsistency,andoptimizingperformance.1)Theysimplifycomplexqueriesbyencapsulatingthemintoreusableviews.2)Viewsenhancesecuritybycontrollingdataaccess.3)Theyensuredataco

How Can I Create a Simple View in MySQL?How Can I Create a Simple View in MySQL?May 16, 2025 am 12:08 AM

TocreateasimpleviewinMySQL,usetheCREATEVIEWstatement.1)DefinetheviewwithCREATEVIEWview_nameAS.2)SpecifytheSELECTstatementtoretrievedesireddata.3)Usetheviewlikeatableforqueries.Viewssimplifydataaccessandenhancesecurity,butconsiderperformance,updatabil

MySQL Create User Statement: Examples and Common ErrorsMySQL Create User Statement: Examples and Common ErrorsMay 16, 2025 am 12:04 AM

TocreateusersinMySQL,usetheCREATEUSERstatement.1)Foralocaluser:CREATEUSER'localuser'@'localhost'IDENTIFIEDBY'securepassword';2)Foraremoteuser:CREATEUSER'remoteuser'@'%'IDENTIFIEDBY'strongpassword';3)Forauserwithaspecifichost:CREATEUSER'specificuser'@

What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!