mysql插入记录的两种方式

1、插入指定列,如果没有列出这个列,自动给null赋值。如果不插入列,设置非空约束,会报错。

2、插入所有列,如果哪个列不想插入值,就需要赋值为null。

实例

insertinto表名values(值,值....);

eg:
insertintoproductvalues(null,'苹果电脑',18000.0,10);
insertintoproductvalues(null,'华为5G手机',30000,20);
insertintoproductvalues(null,'小米手机',1800,30);
insertintoproductvalues(null,'iPhonex',8000,10);
insertintoproductvalues(null,'iPhone7',6000,200);
insertintoproductvalues(null,'iPhone6s',4000,1000);
insertintoproductvalues(null,'iPhone6',3500,100);
insertintoproductvalues(null,'iPhone5s',3000,100);

insertintoproductvalues(null,'方便面',4.5,1000);
insertintoproductvalues(null,'咖啡',11,200);
insertintoproductvalues(null,'矿泉水',3,500);

以上就是mysql插入记录的两种方式,希望对大家有所帮助。更多mysql学习指路:Mysql

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。