插入MySQL时跳过栏 [英] Skip column when inserting into MySQL

查看:56
本文介绍了插入MySQL时跳过栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在表中插入新行时,如何既不知道表中的名称也不知道列的数量时,如何跳过列?

How can I skip a column when inserting a new row into a table without knowing neither the names nor the amount of columns in my table?

使用INSERT (col1, col2) VALUES (1, 2)不可选项,因为在运行时我不知道列数.这些都是根据用户输入计算得出的.

Using INSERT (col1, col2) VALUES (1, 2) is not an option, because I can not know the amount of columns during runtime. It's all calculated from user input.

因此,我在插入时需要跳过第一列(id,PRIMARY KEY auto_increment).

Thus, I need to skip the first column (id, PRIMARY KEY auto_increment) when inserting.

推荐答案

您可以插入而不提供列名,但是必须为所有列提供一些值.

You can insert without giving column names, but you had to give some values for all columns.

INSERT INTO comments 
VALUES (null, 2, 3, 4,null,6) 

CREATE TABLE IF NOT EXISTS `comments` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `imageid` int(10) unsigned NOT NULL DEFAULT '0',
  `uid` bigint(20) unsigned NOT NULL DEFAULT '0',
  `content` text CHARACTER SET utf8,
  `adate` datetime DEFAULT NULL,
  `ip` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
   KEY `ids` (`imageid`,`adate`) USING BTREE
) ENGINE=InnoDB  DEFAULT CHARSET=latin1  ;

这篇关于插入MySQL时跳过栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆