我需要有关如何将此select转换为delete语句的帮助。
SELECT stud_term_sum_div.id_num,
stud_term_sum_div.hrs_enrolled,
stud_term_sum_div.transaction_sts,
student_crs_hist.crs_cde,
student_crs_hist.transaction_sts
FROM stud_term_sum_div,
student_crs_hist
WHERE ( stud_term_sum_div.yr_cde = student_crs_hist.yr_cde ) and
( stud_term_sum_div.trm_cde = student_crs_hist.trm_cde ) and
( stud_term_sum_div.id_num = student_crs_hist.id_num ) and
( ( stud_term_sum_div.yr_cde = '2013' ) AND
( stud_term_sum_div.trm_cde = 'FA' ) AND
( stud_term_sum_div.hrs_enrolled >= 3.00 ) AND
( student_crs_hist.transaction_sts = 'D' ) )
答案 0 :(得分:1)
最直接的转换如下:
DELETE * FROM stud_term_sum_div
WHERE ( stud_term_sum_div.yr_cde = student_crs_hist.yr_cde ) and
( stud_term_sum_div.trm_cde = student_crs_hist.trm_cde ) and
( stud_term_sum_div.id_num = student_crs_hist.id_num ) and
( ( stud_term_sum_div.yr_cde = '2013' ) AND
( stud_term_sum_div.trm_cde = 'FA' ) AND
( stud_term_sum_div.hrs_enrolled >= 3.00 ) AND
( student_crs_hist.transaction_sts = 'D' ) )
但是,在执行之前,请检查WHERE
子句是否确实包含要用于删除的条件。请注意,当WHERE
子句中的属性满足所述条件时,此SQL语句将删除整行(a / k / a记录)。
如果您只想从属性中删除数据(而不是整个记录),则需要使用SQL UPDATE
语句。 (简化)语法如下:
UPDATE <table_name>
SET <attribute1> = <value1>
[, SET <attribute_n> = <value_n>...]
WHERE <conditions on which the record should be updated>
在Bing上搜索,google,&lt;在此处插入您最喜爱的搜索引擎&gt;对于“SQL DELETE”或“SQL UPDATE”应该可以获得所需的所有信息(例如MSDN)。