插入:
INSERT INTO [Demo].[dbo].[Demo] ([Title],[Info])VALUES ('第一條數據標題','內容')
更新:
將BaseData1數據庫Table1表中,ID爲1這條數據的Status的值更改爲0update [BaseData1].[dbo].[Table1] set Status=0 WHERE ID=1
插入或更新的判斷:
if exists(select * from [A_P_T_Com].[dbo].[shopAttribute] where ShopID=182478)
begin
update top(1) [A_P_T_Com].[dbo].[shopAttribute] set Type=9 where ShopID=182478
end
else
begin
insert into [A_P_T_Com].[dbo].[shopAttribute] (ShopID,Type) values (182478,8)
end
表關聯:
列出 A、B表的所有信息,條件是A表的ID號在B表要有記錄,並且該ID在B表的Type值爲1
SELECT * FROM [A_P_T_Com].[dbo].[shop],[A_P_T_Com].[dbo].[shopAttribute]
WHERE [A_P_T_Com].[dbo].[shop].Id=[A_P_T_Com].[dbo].[shopAttribute].ShopID
AND [A_P_T_Com].[dbo].[shopAttribute].Type=1