I would like to use the INSERT INTO
clause to add additional data to a table.
I would like to insert the following Car data into table called Car_data.
Chrysler,Fiat Chrysler,32000,31591,32831,29544,33006,29945,13857,31869,0
Dodge,Fiat Chrysler,29000,110517,117582,104146,90643,88656,43756,71935,0
Ferrari,Ferrari,300000,2585,2585,2585,,2147,2147,2147,
Fiat,Fiat Chrysler,26000,2214,2889,2361,1740,1128,1339,1102,0
Can someone show me how to INSERT INTO dbo.[Car_data]
. The insert script is a follows:
INSERT INTO dbo.[Car_data]
(
Brand
,Autogroup
,[Avg Price]
,[Q1 2019]
,[Q2 2019]
,[Q3 2019]
,[Q4 2019]
,[Q1 2020]
,[Q2 2020]
,[Q3 2020]
,[Q4 2020]
)
VALUES
(
N'' -- Brand - nvarchar(50)
,N'' -- Autogroup - nvarchar(50)
,0 -- Avg Price - int
,0 -- Q1 2019 - int
,0 -- Q2 2019 - int
,0 -- Q3 2019 - int
,0 -- Q4 2019 - int
,0 -- Q1 2020 - int
,0 -- Q2 2020 - int
,0 -- Q3 2020 - int
,0 -- Q4 2020 - int
);
GO
So I would like to know if there is straight forward to insert the Car Data into the Car_data table?
Are you sure this isn't homework?
Try this (substituting these names with your own) :
BULK INSERT dbo.Car_Data FROM 'C:\car_data.csv' WITH (FORMAT='CSV')
Or if you are asking how you do this using copy and paste try this (first 2 rows only):
INSERT INTO dbo.[Car_data]
(Brand ,Autogroup ,[Avg Price] ,[Q1 2019] ,[Q2 2019] ,[Q3 2019],[Q4 2019] ,[Q1 2020] ,[Q2 2020] ,[Q3 2020] ,[Q4 2020])
VALUES
('Chrysler','Fiat' 'Chrysler',32000,31591,32831,29544,33006,29945,13857,31869,0),
('Dodge','Fiat' 'Chrysler',29000,110517,117582,104146,90643,88656,43756,71935,0);