插入:
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