ใช้บล็อกเป็นโน๊ตย่อ หรือบันทึกช่วยจำ เรื่องการเขียน sql

8 มี.ค.54 มีโอกาสจัดการข้อมูลประมาณมาก กับหลายตารางที่มีโครงสร้างต่างกัน
พบว่าคำสั่ง delete กับ truncate ให้ผลใกล้เดียงกันคือ clear ข้อมูลที่เคยทดสอบออกหมด แต่ truncate จะทำให้ auto_increment เริ่มต้นจาก 1 มิใช่ต่อจากเลขเดิมที่เคยมีในตารางนั้น
ส่วนคำสั่งเพิ่มข้อมูลหลายระเบียนเดิมใช้
insert into behavior (bid,bname) values (1,’tom’);
insert into behavior (bid,bname) values (2,’boy’);
แบบใหม่เขียนสั้นลงคือ
insert into behavior (bid,bname) values (1,’tom’), (2,’boy’);
ส่วนการแก้ไขข้อมูลหลายเขตข้อมูลจะใช้ , หลัก set แต่ใช้ and หลัง where
เช่น
update behavior set bsex=0, bname=’jack’ where bid=1 and bgroup=2

ตัวอย่างการ clear ข้อมูลก่อนเปิดใช้จริง
delete from administration;
truncate administration;
truncate behavior;
truncate favorite;
truncate president;
truncate rart;
truncate rart_d;
truncate rdevelop;
truncate rdevelop_d;
truncate reval;
truncate rexecutive;
truncate rexecutive_d;
truncate rother;
truncate rother_d;
truncate rpublish;
truncate rpublish_d;
truncate rresearch;
truncate rresearch_d;
truncate rservice;
truncate rservice_d;
truncate rteaching;
truncate rteaching_d;
truncate ryour;
truncate ryour_d;
truncate salary;