MS SQL數據庫操作總結(不斷更新中...)

插入:

INSERT INTO [Demo].[dbo].[Demo]  ([Title],[Info])VALUES ('第一條數據標題','內容')

更新:

將BaseData1數據庫Table1表中,ID爲1這條數據的Status的值更改爲0

update [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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章