天天看點

資料庫的一些基本操作

update tablename set column=value where column=value
           

首先以王珊老師的《資料庫系統概論》為例(畢竟是經典中的經典),建三個簡單的表,其中構成有連接配接的關系。

隻寫一個建表語句吧。

create table student(
sno int(10)  auto_increment primary key not null,
sname varchar(5),
ssex varchar(2),
sage int(3)
)
           

學生表如上

create table course(
cno int(10)  auto_increment primary key not null,
cname varchar(5),
cxuefen int(3)
)
           

課程表如上

create table student(
sno int(10)   primary key not null,
cno int(10)   primary key not null,
grade int(3))
           

學生課程表如上

foreign key (sno) reference (student.sno)之類的 

我猜應該是沒有問題的!!!

但是應該是添加外間限制的 foreign key!!!

然後是普通的增删改查

然後貌似在mysql中一般是不區分大小寫的,可以自己設定!

增加:

insert into tablename (column1,column2,column3) values(value1,value2,value3)
           

删除:

delete from tablename where column=value
           

查詢:

select tablename.column,..... from tablename
           

更新:

update tablename set column=value where column=value

然後就是開始函數了

因為1=1是恒真式,是以寫條件表達式的時候要好好利用這個表達式1=1

比如我們在拼接查詢語句的時候為了避免報錯可以首先拼接恒真式

select sno,sname,sdept where 1=1,後面的條件

繼續閱讀