php INSERT INTO 语法问题
php INSERT INTO issue with syntax
INSERT INTO Departments (DepartmentID, DepartmentName, Location, Phone, Chair)
VALUES (50, ‘Archival Information’, ‘B479’, 4321, ‘Robin’);
这行得通,但行不通:
INSERT INTO Departments (DepartmentID, DepartmentName, Location, Phone, Chair)
VALUES (50, ‘Archival Information’, ‘B479’, 4321, ‘Robin’),
(51, ‘Information Retrieval’, ‘B431’, 4322, ‘Sheela’),
(52, ‘Information Organization’, ‘B410’, 4323, ‘Craig’),
(53, ‘Information Policy’ ‘B204’, 4324, ‘Michael’),
(54, ‘Information Management’, ‘B219’, 4331, ‘Chris’),
(55, ‘Information Security’, ‘B225’, 4332, ‘Steve’),
(56, ‘Information Technology’, ‘B435’, 4333, ‘Arthur’),
(57, ‘Information Design’, ‘B300’, 4334, ‘Amy’),
(58, ‘Health Informatics’, ‘B428’, 4330, ‘Rav’),
(59, ‘Information Ethics’, ‘B356’, 4320, ‘Simon’);
有什么问题吗?我已经在线检查了语法,这就是我注意到正确语法被输入的方式。
INSERT INTO Departments (DepartmentID, DepartmentName, Location, Phone, Chair)
VALUES
(50, 'Archival Information', 'B479', 4321, 'Robin'),
(51, 'Information Retrieval', 'B431', 4322, 'Sheela'),
(52, 'Information Organization', 'B410', 4323, 'Craig'),
(53, 'Information Policy', 'B204', 4324, 'Michael'),
(54, 'Information Management', 'B219', 4331, 'Chris'),
(55, 'Information Security', 'B225', 4332, 'Steve'),
(56, 'Information Technology', 'B435', 4333, 'Arthur'),
(57, 'Information Design', 'B300', 4334, 'Amy'),
(58, 'Health Informatics', 'B428', 4330, 'Rav'),
(59, 'Information Ethics', 'B356', 4320, 'Simon');
你的单引号不正确,除了第一个
BTW your sql server is important only mssql 2008 or newer and mysql
4.1 or newer supports inserting more then one value with comma separating.
正确的sql查询:
INSERT INTO Departments (DepartmentID, DepartmentName, Location, Phone, Chair)
VALUES (50, 'Archival Information', 'B479', 4321, 'Robin'),
(51, 'Information Retrieval', 'B431', 4322, 'Sheela'),
(52, 'Information Organization', 'B410', 4323, 'Craig'),
(53, 'Information Policy', 'B204', 4324, 'Michael'),
(54, 'Information Management', 'B219', 4331, 'Chris'),
(55, 'Information Security', 'B225', 4332, 'Steve'),
(56, 'Information Technology', 'B435', 4333, 'Arthur'),
(57, 'Information Design', 'B300', 4334, 'Amy'),
(58, 'Health Informatics', 'B428', 4330, 'Rav'),
(59, 'Information Ethics', 'B356', 4320, 'Simon');
@exussum 警告我 mysql 版本,所以,
我编辑了支持的 mysql 版本号 5.5 到 4.1 谢谢。
VALUES (50, 'Archival Information', 'B479', 4321, 'Robin'),
(51, ‘Information Retrieval’, ‘B431’, 4322, ‘Sheela’),
你的第一行使用了单引号,而你的第二行使用了反引号。
在 MySQL 中,反引号是 identifier quote
表示它将内部视为标识符。例如 table 名称。常规引号被视为要插入的数据。
将 wards 上的第 2 行转换为使用 '
而不是 '`'
您在值的第四行(在 'Information Policy'
和 'B204'
之间)缺少一个逗号。更正后它对我有用。
INSERT INTO Departments (DepartmentID, DepartmentName, Location, Phone, Chair)
VALUES (50, ‘Archival Information’, ‘B479’, 4321, ‘Robin’);
这行得通,但行不通:
INSERT INTO Departments (DepartmentID, DepartmentName, Location, Phone, Chair)
VALUES (50, ‘Archival Information’, ‘B479’, 4321, ‘Robin’),
(51, ‘Information Retrieval’, ‘B431’, 4322, ‘Sheela’),
(52, ‘Information Organization’, ‘B410’, 4323, ‘Craig’),
(53, ‘Information Policy’ ‘B204’, 4324, ‘Michael’),
(54, ‘Information Management’, ‘B219’, 4331, ‘Chris’),
(55, ‘Information Security’, ‘B225’, 4332, ‘Steve’),
(56, ‘Information Technology’, ‘B435’, 4333, ‘Arthur’),
(57, ‘Information Design’, ‘B300’, 4334, ‘Amy’),
(58, ‘Health Informatics’, ‘B428’, 4330, ‘Rav’),
(59, ‘Information Ethics’, ‘B356’, 4320, ‘Simon’);
有什么问题吗?我已经在线检查了语法,这就是我注意到正确语法被输入的方式。
INSERT INTO Departments (DepartmentID, DepartmentName, Location, Phone, Chair)
VALUES
(50, 'Archival Information', 'B479', 4321, 'Robin'),
(51, 'Information Retrieval', 'B431', 4322, 'Sheela'),
(52, 'Information Organization', 'B410', 4323, 'Craig'),
(53, 'Information Policy', 'B204', 4324, 'Michael'),
(54, 'Information Management', 'B219', 4331, 'Chris'),
(55, 'Information Security', 'B225', 4332, 'Steve'),
(56, 'Information Technology', 'B435', 4333, 'Arthur'),
(57, 'Information Design', 'B300', 4334, 'Amy'),
(58, 'Health Informatics', 'B428', 4330, 'Rav'),
(59, 'Information Ethics', 'B356', 4320, 'Simon');
你的单引号不正确,除了第一个
BTW your sql server is important only mssql 2008 or newer and mysql 4.1 or newer supports inserting more then one value with comma separating.
正确的sql查询:
INSERT INTO Departments (DepartmentID, DepartmentName, Location, Phone, Chair)
VALUES (50, 'Archival Information', 'B479', 4321, 'Robin'),
(51, 'Information Retrieval', 'B431', 4322, 'Sheela'),
(52, 'Information Organization', 'B410', 4323, 'Craig'),
(53, 'Information Policy', 'B204', 4324, 'Michael'),
(54, 'Information Management', 'B219', 4331, 'Chris'),
(55, 'Information Security', 'B225', 4332, 'Steve'),
(56, 'Information Technology', 'B435', 4333, 'Arthur'),
(57, 'Information Design', 'B300', 4334, 'Amy'),
(58, 'Health Informatics', 'B428', 4330, 'Rav'),
(59, 'Information Ethics', 'B356', 4320, 'Simon');
@exussum 警告我 mysql 版本,所以, 我编辑了支持的 mysql 版本号 5.5 到 4.1 谢谢。
VALUES (50, 'Archival Information', 'B479', 4321, 'Robin'),
(51, ‘Information Retrieval’, ‘B431’, 4322, ‘Sheela’),
你的第一行使用了单引号,而你的第二行使用了反引号。
在 MySQL 中,反引号是 identifier quote
表示它将内部视为标识符。例如 table 名称。常规引号被视为要插入的数据。
将 wards 上的第 2 行转换为使用 '
而不是 '`'
您在值的第四行(在 'Information Policy'
和 'B204'
之间)缺少一个逗号。更正后它对我有用。