如何向mysql添加新行?

时间:2015-10-02 02:55:40

标签: php mysql

我有一个像这样的用户表:

INSERT INTO signup (UID, email, username, fname, lname, bdate, gender)
VALUES
(1, 'sample1@sample1.com', 'johnd', 'john', 'doe', '0000-00-00', 'Male'),
(2, 'sample1@sample2.com', 'marryb', 'marry', 'brown', '0000-00-00', 'Female');

我在记事本上准备了一个新的用户列表,如下所示:

  

(3,' sample3@sample3.com',' alij',' ali',' johnson',' ','男'),
  (4,' sample4@sample4.com',' janew',' jane',' white',' 0000-00 -00','女');

如何使用SQL命令将新用户添加到我的数据库?

2 个答案:

答案 0 :(得分:0)

您已经回答了自己的问题。 SQL是一个INSERT语句,而不是表。它用于将数据插入表中。所以你需要创建表格'注册'如果它还不存在。然后,您只需使用括号中的附加数据集插入。

https://dev.mysql.com/doc/refman/5.1/en/insert.html

答案 1 :(得分:0)

INSERT INTO signup (UID, email, username, fname, lname, bdate, gender,) VALUES (1, 'sample1@sample1.com', 'johnd', 'john', 'doe', '0000-00-00', 'Male');
INSERT INTO signup (UID, email, username, fname, lname, bdate, gender,) VALUES (3, 'sample1@sample2.com', 'marryb', 'marry', 'brown', '0000-00-00', 'Female');
INSERT INTO signup (UID, email, username, fname, lname, bdate, gender,) VALUES (4, 'sample3@sample3.com', 'alij', 'ali', 'johnson', '0000-00-00', 'Male');
INSERT INTO signup (UID, email, username, fname, lname, bdate, gender,) VALUES (5, 'sample4@sample4.com', 'janew', 'jane', 'white', '0000-00-00', 'Female');

或者只是INSERT ALL INTO

INSERT ALL
  INTO signup (UID, email, username, fname, lname, bdate, gender,) VALUES (1, 'sample1@sample1.com', 'johnd', 'john', 'doe', '0000-00-00', 'Male')
  INTO signup (UID, email, username, fname, lname, bdate, gender,) VALUES (3, 'sample1@sample2.com', 'marryb', 'marry', 'brown', '0000-00-00', 'Female')
  INTO signup (UID, email, username, fname, lname, bdate, gender,) VALUES (4, 'sample3@sample3.com', 'alij', 'ali', 'johnson', '0000-00-00', 'Male')
  INTO signup (UID, email, username, fname, lname, bdate, gender,) VALUES (5, 'sample4@sample4.com', 'janew', 'jane', 'white', '0000-00-00', 'Female')
SELECT * FROM dual;

我希望这会有所帮助。