點乙個刪除按鈕的時候,刪除user1表的code=x列的一行,而且刪除另乙個表user1中usercode列值等於x的所有行
因為我是初學,不會儲存過程和什麼觸發器..所以用的笨方法。
我用的是拼接字串,其中最主要的就是在sql = "delete from user1 where code =" + usercode.tostring() + "deletefrom user2 where usercode =" + usercode.tostring();
這一句了 寫兩個delete from 中間不需要空格
一下是在類中的**
public static int deluser(int usercode)
else
return result;
求大神賜教儲存過程咋寫...或者觸發器咋寫,萬一要刪除好幾個表 那我辦法就太笨了,麻煩
一條SQL語句刪除重複的記錄
去面試時,被問到用一條sql語句刪除重複的記錄,當時做不出來,回頭想想,方法如下 新增乙個表,用於測試 create table table1 id int primary key,name char 20 新增樣品記錄 insert into table1 values 1,hello 2,wor...
利用一條SQL從表中抽取一定資料
利用一條sql語句從資料庫表 隨機獲取n條記錄,各資料庫的sql語句略有不同,如下 1 mysql select from table order by rand limit n 以上 效率不高,自己對1000條資料表隨機取10條的測試結果為耗時0.125s,有推薦改為以下 效率有大幅提高,耗時為0...
mysql取兩個資料表其中一條資料
需求 根據特定條件先去取a表的資料,如果a表不存在就取b表的資料 mysql語法為 select case when h.start time is null then g.start time else h.start time end start time,case when h.end tim...