1. 程式人生 > >SQL常見對錶的增刪查改

SQL常見對錶的增刪查改

1.表的建立: create table student //建立表student ( sno char(9) primary key, //定義主碼 sname char(8)unique, //定義sname取唯一值 sex char(2), sage smallint ); 2.刪(刪除student表): drop table student; 3.修改基本表: (向student表增加入學時間列,資料型別為日期時間類) alter table student add s_entrance date; (將年齡sage的資料型別改為整數型別) alter table student alter column sage int; 4.表資料的查詢: ①select * //*查詢表中所有資料 from student;

②select sno,sname from student where sex=’男’; //查詢student表中性別為男的學生學號和姓名 5.表資料的插入: insert into student(sno,sname,sex,sage) values(‘41209310100’,’李三’,’男’,18); //將李三的資訊插入到student表中 6.表資料的修改: update student set sage=22 where sno=’41209310100’; //將學號為41209310100的學生年齡改為22 7.表資料的刪除: delete from student where sno=’41209310100’; //刪除學號為41209310100的學生資訊 注意:刪除表資料時若沒有where語句,該操作會使該表資料清空!