so, I’m trying to create a small database/couple of tables in sqlfiddle using the ms sql server 2017 version. I always get "incorrect syntax near ‘123’". and, I’m not sure what the problem is. Please advise.
CREATE TABLE ProjectIpMapping (
projectId varchar(3),
ip varchar(12));
CREATE TABLE Requests (
sourceIp varchar(12),
destinationIp varchar(12),
projectId varchar(3),
requestId varchar(4),
sizeBits int);
INSERT into ProjectIpMapping (projectId, ip)
(123, 203.0.113.42),
(456, 203.2.56.112),
(165, 197.32.12.43),
(318, 197.32.45.18);
INSERT INTO Requests (sourceIp, destinationIp, projectId, requestId, sizeBits)
VALUES
(203.0.113.42, 197.32.45.18, 318, 1234, 11239),
(203.0.113.42, 326.22.15.19, 123, 1235, 1239),
(203.2.56.112, 197.32.45.18, 165, 1236, 12394),
(197.32.45.18, 326.22.15.19, 123, 1237, 2821),
(197.32.45.18, 821.54.03.20, 318, 1238, 234)
>Solution :
You are missing the VALUES keyword and you are declaring strings as VARCHAR type but you’re not enclosing inside quotes.
CREATE TABLE ProjectIpMapping (
projectId varchar(3),
ip varchar(12)
);
CREATE TABLE Requests (
sourceIp varchar(12),
destinationIp varchar(12),
projectId varchar(3),
requestId varchar(4),
sizeBits int
);
INSERT into ProjectIpMapping (projectId, ip) VALUES
('123', '203.0.113.42'),
('456', '203.2.56.112'),
('165', '197.32.12.43'),
('318', '197.32.45.18');
INSERT INTO Requests (sourceIp, destinationIp, projectId, requestId, sizeBits) VALUES
('203.0.113.42', '197.32.45.18', '318', '1234', 11239),
('203.0.113.42', '326.22.15.19', '123', '1235', 1239 ),
('203.2.56.112', '197.32.45.18', '165', '1236', 12394),
('197.32.45.18', '326.22.15.19', '123', '1237', 2821 ),
('197.32.45.18', '821.54.03.20', '318', '1238', 234 );
Check the demo here.