Coping with sql server2008
Throw an error:
Invalid object name 'Car_Info'.
This is because connecting with wrong database. I checked the connection.The server connected user database. Then I changed it and narrowed down toexact database which I am working on.
Problem solved.
insert into Car_Info(VIN,Car_ID,Brand,Model_year,Sales_type)
select 'WAUAGD4M3GD032946','EE058','A','2016','4MB0A1' union
select 'LFV3A24G0G3003236','EE056','A','2017','4XL06G'
At first, I want to set timestamp as the primary key of the frequentlyupdated tables. Then I realized that the timestamp is used to synchronizebetween transactions. Then I set a auto-increasing number as primary key.
Datetime:
http://www.cnblogs.com/dudu/p/sql-server-datetime-vs-datetime2.html
alter table Engine_Control_Unit add Unit_No int IDENTITY(1,1) NOT NULL
Also Time is a key word in sql server. I changed it into **_time.
insert intoEngine_Control_Unit(Check_time,VIN,Unit_ID,System_name,SW_part_No,SW_version)
select '2017-04-20 11:32:53','WAUAGD4M3GD032946','0001','3.0l V6TFSI','4M0907551','0006' union
select '2017-04-20 11:32:53','WAUAGD4M3GD032946','0002','0D530TSIRdW','4M0927158C','1011' union
select '2017-07-05 15:34:43','LFV3A24G0G3003236','0001','1.8l R4TFSI','4G0906264','0004' union
select '2017-07-05 15:34:43','LFV3A24G0G3003236','0002','0CK18TFSIRdW','4G0927153R','0004'
insert into ECU_Lookup_Sheet(Unit_No,Unit_name)
select '0001','Engine Control Module 1' union
select '0002','Transmission Control Module'
alter table DTC_Report add Report_No int IDENTITY(1,1) NOT NULL
insert into DTC_Report(VIN,Report_time,iDEX_User_name,Report_version)
select 'WAUAGD4M3GD032946','2017-04-20 11:32:53.000','ewanwr0','1.1.0.5'union
select 'LFV3A24G0G3003236','2017-07-05 15:34:43.000','ewanwr0','1.1.0.5'
insert into Service_Key(VIN,SK_date,SK_time,Mileage)
select 'WAUAGD4M3GD032946','2016-07-27','04:44:58.000','364' union
select 'LFV3A24G0G3003236','2017-07-05','10:34:47.000','802'
insert into Local_Sense(Tag_ID,VIN,Pos_date,Pos_time,Pos_x,Pos_y,Pos_z)
select'6002','WAUAGD4M3GD032946','2016-07-27','04:44:58.000','111','222','3' union
select'6003','LFV3A24G0G3003236','2017-07-05','10:34:47.000','333','444','3'
alter table DTC_Report add Report_date date
alter table DTC_Report alter column Report_time time
update DTC_Report set Report_date='2017-04-20' where VIN ='WAUAGD4M3GD032946'
update DTC_Report set Report_date='2017-07-05' where VIN ='LFV3A24G0G3003236'
JOIN reference website:
http://www.cnblogs.com/congtou/archive/2011/07/28/2119299.html
select * from Engine_Control_Unit left join ECU_Lookup_Sheet onEngine_Control_Unit.Unit_ID = ECU_Lookup_Sheet.Unit_ID
select * from
DTC_Report inner join Engine_Control_Unit on DTC_Report.Report_date =Engine_Control_Unit.Check_date inner join Local_Sense on DTC_Report.Report_date= Local_Sense.Pos_date