JAVA入门到精通-第58讲-SQLserver数据类型
Posted 夏至稻花如白练,大暑池畔赏红莲
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JAVA入门到精通-第58讲-SQLserver数据类型相关的知识,希望对你有一定的参考价值。
![](https://image.cha138.com/20210524/a5765e92a8b848b399cb3a7b5ed62f49.jpg)
![](https://image.cha138.com/20210524/6d8750b01c7a42e9bdccbff37fd17774.jpg)
![](https://image.cha138.com/20210524/7dc903e2d8da45e7a8c013ba7231c985.jpg)
![](https://image.cha138.com/20210524/8b03b480011b444ab486b31806dde77e.jpg)
![](https://image.cha138.com/20210524/996cfbeb18884734bdac901a9ad6a54a.jpg)
![](https://image.cha138.com/20210524/22de4d99fafc43ac9b41132e99f24a66.jpg)
![](https://image.cha138.com/20210524/e0bd895b8a3243078675fab36c460c1f.jpg)
![](https://image.cha138.com/20210524/ce070b38833546298d30a36b5ccbc5e6.jpg)
![](https://image.cha138.com/20210524/6bea593d239f4e769b0a12cbdf6e836d.jpg)
![](https://image.cha138.com/20210524/2ffed23c32b84d42a7979e2dd6186a18.jpg)
![](https://image.cha138.com/20210524/786dc897a8014bfdadce7cb9de601255.jpg)
![](https://image.cha138.com/20210524/397a3fd3b20f4b588470986edc65f0d9.jpg)
![](https://image.cha138.com/20210524/40734589d8be4bb48cb260042bfc5fa9.jpg)
![](https://image.cha138.com/20210524/38a200582b5342438ca9ff0d5a7cb933.jpg)
![](https://image.cha138.com/20210524/ac9c5b63b09044b680d0e0626680c525.jpg)
![](https://image.cha138.com/20210524/12123779a164426380516990b70a5bc5.jpg)
![](https://image.cha138.com/20210524/00bcdc0002734325984db00d5a6fe601.jpg)
![](https://image.cha138.com/20210524/9ba001c3ab864a1890c76a866a512094.jpg)
![](https://image.cha138.com/20210524/3211978ffdd5418f9661ba4dbca5b8c0.jpg)
![](https://image.cha138.com/20210524/66d395b6a3ee4987aaea93a90b6cb83d.jpg)
![](https://image.cha138.com/20210524/b2a5f141a2ad4b10987a61ce2d854442.jpg)
![](https://image.cha138.com/20210524/58e67eea05b042518c13c89de55e2955.jpg)
![](https://image.cha138.com/20210524/d1c1557aea3847a1bd81cd9e84dfd45a.jpg)
日期类型
datetime(表示日期)
timestamp(时间戳)
一般情况下 用datetime表示日期
--sql server为我们提供一个专门的时间函数
getdate()
create table spname--建表
(bir datetime)--字段
insert into spname values(getdate())--添加时间
图片
image保存图片,但是用的很少,一般用路径保存图片,在软件公司往往使用图片服务器和图床技术
视频
binary字段可以存放,但是我们往主,将视频文件保存在文件服务器上,sql server中只保留文件路径,存取效率高。
表的管理--怎样创建表
建表(公司管理系统)
--职员表
sql server建议表的设计者,最好给表定义一个主键,用来标示唯一的一条记录。
1、主键(primary key),不能够重复出现;
2、主键必需给值,换言之主键不能为null
3、主键可以修改,但不能修改为同名的,同时要明确字段不有重复,否则报错。
表的管理--查询
查询表是对表操作的最重要的操作,这个后面详细讲解
表的管理--添加数据
所有字段都插入
insert into emp values(7521,\'ward\',\'salesman\',7698,\'1981-2-22\',1250.00,500.00,30)
插入部分字段(语法)
insert into 表名 (字段名1,字段名2,...) values (对应字段数据1,对应字段数据2,...)
表的管理--修改数据
改一个字段(语法)
update 表名 set 字段名=\'新值\' where 字段=\'值\'
例:update student set sex=\'女\' where xh=\'A001\'
update clerk set age=38 where cleName=\'贾政\'
修改多个字段(语法)
update 表名 set 字段名1=\'新值\',字段名2=\'新值\'... where 字段=\'值\'
例:update student set sex=\'男\',birthday=\'1980-04-01\' where xh=\'A001\'
update clerk set cleName=\'薛蟠\',age=40 where cleId=2
修改含有null值的数据(语法)
update 表名 set 字段名=\'新值\' where 字段 is null
例:update clerk set cleName=\'薛宝钗\' where age is null
表的管理--删除数据
删除全部数据
delete from 表名
删除指定数据
delete from 表名 where 字段名=\'值\'
删除多个指定数据(and是条件满足,or是前提条件不满足时使用)
delete from 表名 where 字段名1=\'值\' and 字段名2=\'值\' and或or ...
表的基本查询--介绍(重点)
select语句在软件编程中非常的有用,要好好掌握。
介绍主键和外键
主键,一张表中只能有一个主键
1、主键(primary key),不能够重复出现;
2、主键必需给值,换言之主键不能为null
3、主键可以修改,但不能修改为同名的,同时要明确字段不有重复,否则报错。
外键
1、外键只能指向主键
2、外键和主键的数据类型要一致
以上是关于JAVA入门到精通-第58讲-SQLserver数据类型的主要内容,如果未能解决你的问题,请参考以下文章