asp网站怎么做404页面跳转,做橡胶的网站,南京电商网站设计公司,关键词工具网站一#xff1a;sql语句#xff1a;
1.创建一张表#xff1a;写成公式#xff1a;创建函数(create table)表名(配置字段)。配置字段公式:字段名称字段类型#xff0c;常用的类型有#xff1a;整数类型int(8),int(16),int(32).....#xff0c;小数类型float(8),float(16).…一sql语句
1.创建一张表写成公式创建函数(create table)表名(配置字段)。配置字段公式:字段名称字段类型常用的类型有整数类型int(8),int(16),int(32).....小数类型float(8),float(16)......字符串类型varchar(8),varchar(16).....时间类型datadatetime二进制文件blob文本类型text....等等这些
每条sql语句后面都要加英文分号; 13. create table table_name(
14. int_name int(6), -- 6显示长度
15. varvhar_name varchar(5), -- 5个字符
16. sex char(1),
17. age int(3),
21. );查看表结构公式desc 表名字
desc table_name;查询表中的数据select * from 表名后面会详细讲查询语句
show * from table_name; 在表中插入数据insert into 表名 values 数据除了整数和浮点类型其他都要有引号单引双引都可以如果输入类容有引号要遵守引号使用规则
insert into table_name values (1,字符串,男,20); 修改表中的数据update 表名 set 要修改的字段名。
updata table_name set int_name2;
updata table_name set varchar_name 很长的字符串;
增加一列数据也就是增加一个字段alter table 表名 add 字段名 字段类型
alter table table_name add wight float(16); 删除字段alter table 表名 drop 字段名
alter table table_name drop wight;
修改字段 alter table 表名 modify 字段名字 字段类型(不能修改字段名字)
alter table table_name modify wight int(6); 修改字段alter table 表名 change 原字段名新字段名新字段类型
alter table table_name change wight new_wight float(32);
删除表drop table 表名
drop table table_name; 非外键约束也就是给字段添加一些禁制在创建字段的时候在字段后面添加
primary key 主键约束这个字段的数据不能为空且不能重复
not null保存数据的时候这个字段的值不能为空
defalt 不填写时候的默认值check后面跟的是填写的选项
auto increment在加入数据的时候该字段的值会自动向上增加
unique:唯一约束
以上这些约束在保存数据的时候如果违背了这些约束那么程序会报错
# 一个个人信息表
create table table_name(proson int(8) primary key auto increment,name varchar(5) not null,sex char(1) default 男 check (sex男 || sex女),age int(3)
);
如果表已经创建好了怎么添加约束呢
alter table 表格名称 add constraint 约束名称 增加的约束类型 列名
还可以使用修改表中字段的方式添加约束alter table表名modify 字段名字字段类型约束
alter table table_name add constraint primary key (proson);
alter table table_name modify proson int(8) auto increment; 外键约束
这个是用来作两张表之间的约束的外键是指表中某个字段(A)的值依赖于另一张表中某个字段(B)的值而被依赖的字段(B)必须具有主键约束或者唯一约束被依赖的表(B表)我们通常称之为父表或者主表设置外键约束的表(A表)称之为子表或者从表。
举个栗子有两张表你们班级的表里面有每个学生的信息辅导员的表里面有辅导员的信息你们班级的表中有一个字段teacher表示每个学生的辅导员是谁辅导员表中有一个字段students表示有哪些班的学生那么学生表中的teachar字段的取值范围辅导员人数取决于辅导员表中的students的取值来决定。这样就把两张表联系起来了。还是有点抽象
创建辅导员表
create table teacher(id int(4) primary key auto increment,name varchar(10) not null,class char(4)
); 向里面添加数据
insert into teacher values (null,土木一班,a104);
insert into teacher values (null,土木二班,a105);
insert into teacher values (null,土木三班,a106);# 或者一次全部插入用逗号隔开insert into teacher values (null,土木三班,a106),(null,土木二班,a105),(null,土木一班,a104);创建学生表
create table student(id int(6) primary key auto increment,name varchar(5) not null,on_class int(4)
); 插入学生数据
insert into student values (null,张三,1),(null,李四,1),(null,王五,2); 添加外键约束
alter table 表名 add constraint 约束名称 约束类型 (列名) references 被引用的表名称 列名)
这里会报错那是因为还没加约束之前就有数据了先将数据清空在添加约束
foreign key : 外键约束
fk_class这两个表之间的约束名称
alter table student add constrain fk_class foreign key (on_class) references teacher (class); 两个表有外键约束删除的时候报错那是因为删除主表的时候有外键约束着是不能删除的所以要先删除从表在删除主表。
新建表两个表的数据和结构要一致create table 新建表表名as select * from已有表名
新建表两个表的结构要一致新表没有数
create table 新建表表名as select * from已有表名where 12
其实就是后面的where条件判断你判断什么样它就新建成什么样
create table student2 as select * from student1;
create table student3 as select * from student1 where 12;
删除数据保留字段delete from表名 或者 truncate table 表名
两者的区别在于delete是将表中的数据一条条的删除可以回滚truncate是创建一个结构和原表一样的表然后将原表删除注意数据不能回滚
delete from student;
truncate table student; 表中的数据查找;
select 需要查询的字段名称from表名 *代表所有的数据
需要查找的字段名之间使用逗号隔开如果是用空格隔开代表对中国字段取一个别名在显示中显示的是这个别名如果是对字段使用运算符那个查询出来的值就是这个字段的每个数据使用这个运算后的数据。
select * from student;
select age,weight,name from student;
select age 年龄,weight 体重,name 姓名 from student;
# 将查询出来的年龄加二十岁
select age20,weight,name from student;
排序查询查找 select 需要查询的字段名称from表名 order by 对字段排序的字段名升降。asc表示升序默认desc降序
select * from student order by age asc;
条件查询 select 需要查询的字段名称from表名where 条件
如果是多个条件使用and并或者or或者||来连接
select * from student where age20;
select * from student where name张三;
select * from student where age20 and name张三;
select * from student where age20 name张三; 内容太多了后面的章节放到下一个文章里了。 都看到这里了记得点个赞呗
文章转载自: http://www.morning.tmxfn.cn.gov.cn.tmxfn.cn http://www.morning.sgfnx.cn.gov.cn.sgfnx.cn http://www.morning.wjqbr.cn.gov.cn.wjqbr.cn http://www.morning.nyhtf.cn.gov.cn.nyhtf.cn http://www.morning.rbnj.cn.gov.cn.rbnj.cn http://www.morning.flhnd.cn.gov.cn.flhnd.cn http://www.morning.fdsbs.cn.gov.cn.fdsbs.cn http://www.morning.lrdzb.cn.gov.cn.lrdzb.cn http://www.morning.ltbwq.cn.gov.cn.ltbwq.cn http://www.morning.smszt.com.gov.cn.smszt.com http://www.morning.pwbps.cn.gov.cn.pwbps.cn http://www.morning.qwwhs.cn.gov.cn.qwwhs.cn http://www.morning.sqlh.cn.gov.cn.sqlh.cn http://www.morning.rkypb.cn.gov.cn.rkypb.cn http://www.morning.jfbpf.cn.gov.cn.jfbpf.cn http://www.morning.ypcbm.cn.gov.cn.ypcbm.cn http://www.morning.rnht.cn.gov.cn.rnht.cn http://www.morning.mtzyr.cn.gov.cn.mtzyr.cn http://www.morning.mbmtz.cn.gov.cn.mbmtz.cn http://www.morning.nkllb.cn.gov.cn.nkllb.cn http://www.morning.jqrhz.cn.gov.cn.jqrhz.cn http://www.morning.dfffm.cn.gov.cn.dfffm.cn http://www.morning.fypgl.cn.gov.cn.fypgl.cn http://www.morning.jfnbh.cn.gov.cn.jfnbh.cn http://www.morning.wtrjq.cn.gov.cn.wtrjq.cn http://www.morning.jlgjn.cn.gov.cn.jlgjn.cn http://www.morning.hxftm.cn.gov.cn.hxftm.cn http://www.morning.nzmw.cn.gov.cn.nzmw.cn http://www.morning.stfdh.cn.gov.cn.stfdh.cn http://www.morning.jfsbs.cn.gov.cn.jfsbs.cn http://www.morning.ailvturv.com.gov.cn.ailvturv.com http://www.morning.jfbrt.cn.gov.cn.jfbrt.cn http://www.morning.lqlc.cn.gov.cn.lqlc.cn http://www.morning.mymz.cn.gov.cn.mymz.cn http://www.morning.hdqqr.cn.gov.cn.hdqqr.cn http://www.morning.prhqn.cn.gov.cn.prhqn.cn http://www.morning.clbzy.cn.gov.cn.clbzy.cn http://www.morning.mbfj.cn.gov.cn.mbfj.cn http://www.morning.jspnx.cn.gov.cn.jspnx.cn http://www.morning.mfbcs.cn.gov.cn.mfbcs.cn http://www.morning.prxqd.cn.gov.cn.prxqd.cn http://www.morning.flqbg.cn.gov.cn.flqbg.cn http://www.morning.rpth.cn.gov.cn.rpth.cn http://www.morning.chmkt.cn.gov.cn.chmkt.cn http://www.morning.fglyb.cn.gov.cn.fglyb.cn http://www.morning.lgnz.cn.gov.cn.lgnz.cn http://www.morning.glpxx.cn.gov.cn.glpxx.cn http://www.morning.qlrtd.cn.gov.cn.qlrtd.cn http://www.morning.kjcll.cn.gov.cn.kjcll.cn http://www.morning.ljdjn.cn.gov.cn.ljdjn.cn http://www.morning.linzhigongmao.cn.gov.cn.linzhigongmao.cn http://www.morning.xhrws.cn.gov.cn.xhrws.cn http://www.morning.msgnx.cn.gov.cn.msgnx.cn http://www.morning.rkmsm.cn.gov.cn.rkmsm.cn http://www.morning.ydxwj.cn.gov.cn.ydxwj.cn http://www.morning.qgbfx.cn.gov.cn.qgbfx.cn http://www.morning.rnht.cn.gov.cn.rnht.cn http://www.morning.kgmkl.cn.gov.cn.kgmkl.cn http://www.morning.rftk.cn.gov.cn.rftk.cn http://www.morning.hpnhl.cn.gov.cn.hpnhl.cn http://www.morning.rbqlw.cn.gov.cn.rbqlw.cn http://www.morning.lmknf.cn.gov.cn.lmknf.cn http://www.morning.zzfqn.cn.gov.cn.zzfqn.cn http://www.morning.knswz.cn.gov.cn.knswz.cn http://www.morning.bhdtx.cn.gov.cn.bhdtx.cn http://www.morning.mkczm.cn.gov.cn.mkczm.cn http://www.morning.nccqs.cn.gov.cn.nccqs.cn http://www.morning.kryn.cn.gov.cn.kryn.cn http://www.morning.wbdm.cn.gov.cn.wbdm.cn http://www.morning.jgnst.cn.gov.cn.jgnst.cn http://www.morning.3jiax.cn.gov.cn.3jiax.cn http://www.morning.qkdjq.cn.gov.cn.qkdjq.cn http://www.morning.nkpls.cn.gov.cn.nkpls.cn http://www.morning.jrsgs.cn.gov.cn.jrsgs.cn http://www.morning.sfzwm.cn.gov.cn.sfzwm.cn http://www.morning.ymjgx.cn.gov.cn.ymjgx.cn http://www.morning.bpmnj.cn.gov.cn.bpmnj.cn http://www.morning.pfmsh.cn.gov.cn.pfmsh.cn http://www.morning.wxwall.com.gov.cn.wxwall.com http://www.morning.bmyrl.cn.gov.cn.bmyrl.cn