插入值而不设置主键
我得到了最小的数据库
CREATE TABLE IF NOT EXISTS `users` (
`id` int(8) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
`pass` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
`reg_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`),
UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=40 ;
然后我尝试插入新用户,只设置用户名/电子邮件/密码
then i try to insert new user, setting only username/email/pass
"INSERT INTO users
SET name='user_name', email='users_email', `pass = 'users_top_secret_pass."';
"INSERT INTO
users
SET name='user_name', email='users_email', `pass = 'users_top_secret_pass."';
或者每次我需要插入新的 id 时,例如:
or every time i ned insert new id like:
INSERT INTO `users` (`id`, `name`, `email`, `pass`, `reg_time`) VALUES
(1, 'user', 'user@server.com', 'pass', '2016-01-31 03:10:13');
姓名和电子邮件是唯一的,时间是默认的当前时间戳,我不需要测试它们.这很好,但我如何插入 ID,我需要它吗?
name and email are UNIQUE, time is default current timestamp and i no need to test them. This is good but how i can be insert id, and does i need it?
在本地 phpmyadmin 上测试没有给我任何新东西.
testing on local phpmyadmin gives me nothing new.
upd: 删除了带有 php 函数的过时代码,只有 sql.
upd: removed outdated code with php functions, only sql.
omg,只要设置为 null 就行了!!!!
omg, just setting null, and it good works!!!!
INSERT INTO `users` (`id`, `name`, `email`, `pass`, `reg_time`) VALUES
(null, 'user', 'user@server.com', 'pass', null);