数据库的一些基本操作

来源:互联网 发布:360数据恢复大师损坏 编辑:程序博客网 时间:2024/05/05 06:49

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,后面的条件

原创粉丝点击