iKcamp|基于Koa2搭建Node.js实战(含录像)☞ 解析JSON

摄像地址:https://www.cctalk.com/v/15114923886141

壹.暗许约束
2.主键约束,(唯一约束+非空约束),
设置了主键的字段在赋值的时候不可能重复,stuID为主键则一,下一个就不能为一
三.唯壹约束(允许一行为空),
4.check约束
5.主外建约束 (主表 子表)一对多

图片 1

累加完整性约束
外键约束:
学员基本音讯表(主表)的学生编号是主键
检查实验战表表的上学的小孩子(子表)的数码是外键
2个表在分裂的关联合中学既能够是主表又有啥不可是子表
主外建是1对多

JSON 数据

笔者颠倒了全方位世界,只为摆正你的倒影。

前方的作品中,大家早已形成了花色中普遍的题目,比如
路由请求结构分层视图渲染静态资源等。
那么,JSON 呢?JSON
格式数据的传输,已经尖锐到了作者们的码里行间,脱离了 JSON
的人也许是悲苦的。那么,复合吧!

图片 2

”数据字典“

怎么样设置 JSON 格式

震古烁今的武术家——李小龙(ブルースリー)先生——说过如此一段话:

Empty your mind, Be formless,shapeless like water. 
You put water in a cup, it becomes the cup.
You put water in a bottle, it becomes the bottle. 
You put water in a teapot , it becomes the teapot. 
Water can flow or crash. 

翻译成普通话意思正是:

清空你的思想,像水一样无形。
你将水倒入水杯,水就是水杯的形状。
你将水倒入瓶子,水就是瓶子的形状。
你将水倒入茶壶,水就是茶壶的形状。
你看,水会流动,也会冲击。

在数量传输进程中,传输的财富都足以称为『数据』,而『数据』之所以浮现出不相同的形象,是因为大家早就设置了它的格式。

传输的数据像是『水』1样,未有别的的格式和造型。

笔者们的设置像是『器』一样,赋予它内定的形制。

据此,大家只须要设置把数量挂载在响应体 body
上,同时告诉客户端『重临的是 JSON 数据』,客户端就会安分守纪 JSON
来分析了。代码如下:

ctx.set("Content-Type", "application/json")
ctx.body = JSON.stringify(json)

哪一个是外键表,就给他加上海外国语大学建约束
3个相同:一 外键表外键与主键数据类型1致(语法3头)
2 长度:外键>=主键表;长了也从未意义
三 名称相同。

领取中间件

大家把上边的代码提取成三个中间件,那样更利于代码的维护性和增添性

日增文件 /middleware/mi-send/index.js

module.exports = () => {
  function render(json) {
      this.set("Content-Type", "application/json")
      this.body = JSON.stringify(json)
  }
  return async (ctx, next) => {
      ctx.send = render.bind(ctx)
      await next()
  }
}

注意: 目录不设有,要求协调成立。

代码中,我们把 JSON 数据的处理形式挂载在 ctx 对象中,并起名称为
send。当大家须要重返 JSON 数据给客户端时候,只必要调用此措施,并把
JSON 对象作为参数字传送入到点子中就行了,用法如下:

ctx.send({
  status: 'success',
  data: 'hello ikcmap'
})

万一sql语句写的错误很多,只需求看率先行和尾声一行错误。
只要不多,就仔细看下。

利用中间件

代码的完毕进度和调用方法大家曾经清楚了,现在我们要求把那在那之中间件应用在品种中。

  1. 增Gavin件 middleware/index.js,用来集中调用全数的中间件:

    const miSend = require(‘./mi-send’)
    module.exports = (app) => {
    app.use(miSend())
    }

  2. 修改 app.js,扩大中间件的引用

    const Koa = require(‘koa’)
    const path = require(‘path’)
    const bodyParser = require(‘koa-bodyparser’)
    const nunjucks = require(‘koa-nunjucks-2’)
    const staticFiles = require(‘koa-static’)

    const app = new Koa()
    const router = require(‘./router’)

    const middleware = require(‘./middleware’)

    middleware(app)

    app.use(staticFiles(path.resolve(__dirname, “./public”)))

    app.use(nunjucks({
    ext: ‘html’,
    path: path.join(__dirname, ‘views’),
    nunjucksConfig: {

    trimBlocks: true
    

    }
    }));

    app.use(bodyParser())
    router(app)
    app.listen(3000, () => {
    console.log(‘server is running at http://localhost:3000‘)
    })

通配符—-

中间件迁移

随着项目标步步完善,将会发生有越多的中间件。大家把 app.js
中的中间件代码迁移到 middleware/index.js 中,方便前期维护扩张

  1. 修改 app.js

    const Koa = require(‘koa’)
    const app = new Koa()
    const router = require(‘./router’)

    const middleware = require(‘./middleware’)

    middleware(app)
    router(app)
    app.listen(3000, () => {
    console.log(‘server is running at http://localhost:3000‘)
    })

  2. 修改 middleware/index.js

    const path = require(‘path’)
    const bodyParser = require(‘koa-bodyparser’)
    const nunjucks = require(‘koa-nunjucks-2’)
    const staticFiles = require(‘koa-static’)

    const miSend = require(‘./mi-send’)
    module.exports = (app) => {
    app.use(staticFiles(path.resolve(__dirname, “../public”)))

    app.use(nunjucks({

    ext: 'html',
    path: path.join(__dirname, '../views'),
    nunjucksConfig: {
      trimBlocks: true
    }
    

    }));

    app.use(bodyParser())
    app.use(miSend())
    }

末尾我们还会支付越多的中间件,比如日志记录、错误处理等,都会放在
middleware/ 目录下处理。

下1篇:记录日志——开发日志中间件,记录项目中的各类花样新闻

图片 3

图片 4

上1篇:iKcamp新学科推出啦~~~~~iKcamp|基于Koa2搭建Node.js实战(含摄像)☞
处理静态能源

select * from employee
— 插入一条忘记加入的字段 直接在表的背后添上add
–alter table employee add emName varchar(20) not null
alter table employee
add constraint PK_emId primary key (emId)
alter table employee
add constraint CK_age CHECK(age between 20 and 55)
alter table employee
add constraint DF_address default(‘地址不详’) for address
alter table employee
add constraint UQ_emName unique (emName)
–外键表
alter table employee
add constraint FK_emtypeId
foreign key(emtypeId) references mangertype(mantypeId)
标示列能够不是主键,种子和自增量必须是int,标示列不能够编辑
先自增,再作证,最终插入
在数额涉嫌图里 带钥匙的一方是主键表

引入: 翻译项目Master的自述:


1. 干货|人人都以翻译项指标Master

插入(insert)
1.匹配,
2.多行数据
备份表 select * into student1 from student
就生成一个新的student一

二. iKcamp出品微信小程序教学共5章1六小节约外汇总(含录制)

select * into student1 from student
select * from student1
–将字段名备份,可是所建的束缚未有
select stuNoid,stuName,sex,age,address into student2 from student
select * from student2
–将字段名更改,加as即可
select stuNoid as haha,stuName as gaga,sex as hello,age,address into
student3 from student
select * from student3
select * from student1
use wangwang
go
create table employee
(
empId int identity primary key,
empName varchar(20) not null,
sex bit not null,
age int ,
address varchar(20)

)
go
select * from employee
—接下来将student一表中的数值插入到employee中
/*insert into employee
(empId,empName,sex,age,address)
select
(stuNoId,stuName,sex,age,address)
from stdent1
where age>20
*/
—-插入多行数据union方法
insert student1
(stuNoId,stuName,sex,age,address)
select–不帮助default关键字要用‘’括起来,当两行数据一致时,暗中认可为一行
‘1’,’liuzhao’,’1′,’31’,’default’ union
select
‘1’,’liu’,’1′,’28’,’default’ union
select
‘1’,’zhao’,’1′,’31’,’default’
select * from student1

select * from student1 order by age desc(asc)

破绽百出查询
alter table student add groupId int
select * from student
insert student
(stuNoId,stuName,sex,age,address)
select
‘5’,’zhaoliu’,’1′,’30’,’南昌路’ union
select
‘6’,’zhao’,’1′,’31’,’南路’ union
select
‘7’,’liu’,’1′,’32’,’昌路’

—模糊查询
select * from student where address like ‘%南%’
select * from student where stuName like ‘wangwu[2-4]’
select * from student where stuName like ‘wangwu[^2-4]%’–取反
–加上% 可以将wangwua查出来

select * from student where stuName like ‘wangwu[^2-4]%’

use wangwang
go
create table person
(
perId int identity primary key,
personId int not null–身份证
)
go
–给身份证添加约束,假设身份证伍位数字
/*select * from person
alter table person
add constraint CK_personId CHECK(personId like
[0-4],[0-4],[0-4],[0-4],[0-4])
go*/
–更改
update student set age=age+1
select * from student where groupId=1
update student set age=age+2,stuName=stuName+’mm’
where groupId=1
–删除
delete from student where groupId=1
select * from student

delete from student– 删除表

truncate table student–删除表(效率快 )

SQL 结构化查询语言

T-Sql是SQL的做实版

查询:
一.基础查询贰.聚合函数三.链接查询4.子查询
–更改
update student set age=age+1
select * from student where groupId=1
update student set age=age+2,stuName=stuName+’mm’
where groupId=1
–删除
delete from student where groupId=1
select * from student

delete from student– 删除表
truncate table student–删除表(效率快 )
——————————-查询
use wangwang
go
select * from student where address=’南昌路’
/*select
colname1 as 别名,
colname2 as 别名,
from
tableName
where
条件
group by
分组
having
分组后的筛选
order by
排序
*/
–起别名

select *,’姓名’=stuName from student
select *,stuName as ‘as用法’ from student
–给表起名
select *,stuName as ‘as用法’ from student as Stu
alter table student add haha varchar(20)
select * from student
update student set haha=’mm’ where age>31
select * from student where haha is null
–string a=null与a=”是不1致的 null与空
select * from student where haha is null
select * from student where haha=”
select * from student order by stuNoId asc
——————-分页处理,关键字–top–percent
select top 5 * from student–每页出现伍行
select top 50 percent * from student–每页出现总体的百分之n,进壹法
–排序
select * from student order by age desc–降序号
select * from student order by stuNoId asc–升序
—–函数。
select ‘aaa’ as ‘列明’
–查询an在背后的瑞典语中出现的种类
select CHARINDEX(‘an’,’my name is wangwang’)
–查询an在后边的意大利共和国语中冒出的系列,前边十六个不算,从第三伍早先查找
select CHARINDEX(‘an’,’my name is wangwang’,14)
—–查询长度
select LEN(‘123456’)
select address,LEN(address) as ‘ cahngdu’ from student
———–ltrim()可取空格
select * from student where ltrim(address)=’ 天津路’–左空格
select * from student where ltrim(ltrim(address))=’ 鹿特丹路’–俩边空各
—截取字符串right
select SportageIGHT(‘sgdsggueui’,四) as ‘截取后显得’
select left(‘sgdsggueui’,肆) as ‘截取后展现’
———-替换
select replace(‘sfsfhufhsh’,’sh’,’AA’)–将sh换成AA
select replace(‘sfsfhufhsh’,’s’,’9′)–将sh换成AA
————日期函数
select GETDATE()–获得当前几天期
select DATEADD(DD,一千0,’玖三-07-2二’)–活20000天
select DATENAME(DW,GETDATE())–今日星期几
select DATENAME(WW,GETDATE())–明天是二〇一9年的第几周
select * from student
select convert(varchar(2),age)+address as ‘新的列明’ from student
select age + convert( int,address) as ‘新的列明’ from student–有错误


案例1
create table card
(
cId int identity primary key,
CaId varchar(20) not null
)
go
insert card values (‘fifuejf789io0i658’)

select * from card
update card set CaId = replace(CaId,’i’,’1′)

–update replace(CaId,’i’,’1′) from card

select REPLACE(replace(CaId,’i’,’1′),’o’,’0′) from card
select * into card2 from card
select * from card2

update card2 set card=REPLACE(REPLACE(CaId,’i’,’1′),’o’,’0′)

SQL编程
变量分为:1.局地变量,以@符号前缀,先注明再赋值
赋值:set @变量名=值 select @变量名=值
set @name=zhangsan
select studentNo from student where studentName=@name
李文才:
declare @name varchar(8)
set @name=’李文才’
select @No=studentNo from student where studentName=@name

declare @No int//定义
print’学号’+@No
询问出学号+-一的隔壁的校友。
select * from student where student.studentNo=@No+1 or
student.studentNo=@No-1


insert into Class(GradeId,ClassID) values (4,’201′)

@@IDENTITY

DECLARE @TAG VARCHAR(1)
SET @TAG=’*’
PRINT @TAG+@TAG
PRINT @TAG+@TAG+@TAG
PRINT @TAG+@TAG+@TAG+@TAG
——DECLARE @xuehao int
set @xuehao =20011
select * from student where studentNo=@xuehao//学生记录查出来

declare @year int
set @year=DateDiff(DY,’1996-8-7′,getdate())/365;年份
select * from student where student.brondate=@year+1 or
student.brondate=@year-1;


create database MySchool
on primary
(
name = ‘MySchool_data’,
filename = ‘D:\project\MySchool_data’,
size = 10mb,
maxsize = 100mb,
filegrowth=15%
)
log on
(
name = ‘MySchool_log’,
filename = ‘D:\project\MySchool_log’,
size = 3mb,
maxsize = 20mb,
filegrowth=1mb
)

if exists(select * from sysobjects where name = ‘Student’)
drop table student
create table dbo.Student(
StudentNo int NOT NULL,
LoginPwd nvarchar(50) NOT NULL,
StudentName nvarchar(50) NOT NULL,
sex bit NOT NULL,
GradeId int NOT NULL,
Phone nvarchar(50) NULL,
Address nvarchar(255) NULL,
BornDate datetime NOT NULL,
Email nvarchar(50) NULL,
IdentityCard varchar(18) NOT NULL
)

if exists(select * from sysobjects where name = ‘Subject’)
drop table subject
create table dbo.Subject(
SubjectNO int IDENTITY(1,1) NOT NULL,
SubjectName nchar(50) NOT NULL,
ClassHour int NOT NULL,
GradeId int NOT NULL
)

if exists(select * from sysobjects WHERE name = ‘Result’)
drop table Result
create table dbo.Result(
StudentNo int NOT NULL,
SubjectNo int NOT NULL,
StudentResult int NOT NULL,
ExamDate datetime NOT NULL
)

if exists(select * from sysobjects where name = ‘Grade’)
drop table Grade
create table Grade(
GradeId int IDENTITY(1,1) NOT NULL,
GradeName nvarchar(50) NOT NULL
)

–向Grade表插入数据
INSERT INTO Grade VALUES(‘S1’)
–向Subject表插入数据
INSERT INTO Subject VALUES(‘Winforms’,20,1)

–向Student表插入数据
INSE纳瓦拉T INTO Student
VALUES(‘一千0′,’GuoJing’,’曾诚’,一,一,0208876贰十6,’圣路易斯市河西区’,’一九八八-0九-08
00:00:00′,’GuoJing@sohu.com’,11111一)

–向Result表插入数据
INSERT INTO Result VALUES(‘10001′,2,70.6,’2013-02-15 00:00:00’)


USE master –设置当前数据库为master,以便访问sysdatabases表
GO
IF EXISTS(SELECT * FROM sysdatabases WHERE name =’MySchool’)
DROP DATABASE MySchool
GO

CREATE DATABASE MySchool
ON (
name=’MySchool_data’,
FILENAME=’F:\project\MySchool_data.mdf’,
SIZE=10mb, –主数据文件的发端大小
MAXSIZE=拾0mb, –主数据文件增加的最大值
FILEGROWTH=壹⑤% –主数据文件的增加率
)
LOG ON
(
/*–日志文件的切切实实描述,各参数含义同上–*/
NAME=’MySchool_log’,
FILENAME=’F:\project\MySchool_log.ldf’,
SIZE=3mb,
MAXSIZE=20mb, –日志文件拉长的最大值
FILEGROWTH=1mb
)
GO

 

/*–查询获得Student表的消息–*/
USE MySchool
GO

SELECT * FROM sysobjects

/*–案例:使用SQL语句删除表Student学生–*/
IF EXISTS(SELECT * FROM sysobjects WHERE name=’Student’)
DROP TABLE Student
/*–学时2–*/
/*–案例:使用SQL语句创设Student表–*/
CREATE TABLE [dbo].[Student](
[StudentNo] [int] NOT NULL,
[LoginPwd] [nvarchar](50) NOT NULL,
[StudentName] [nvarchar](50) NOT NULL,
[Sex] bit NOT NULL,
[GradeId] [int] NOT NULL,
[Phone] [nvarchar](50) NULL,
[Address] [nvarchar](255) NULL,
[BornDate] [datetime] NOT NULL,
[Email] [nvarchar](50) NULL,
[IdentityCard] [varchar](18) NOT NULL
)
GO

/*–案例:使用SQL语句创造Subject科目表–*/
IF EXISTS(SELECT * FROM sysobjects WHERE name=’Subject’)
DROP TABLE Subject
CREATE TABLE [dbo].[Subject](
[SubjectNo] [int] IDENTITY(1,1) NOT NULL,
[SubjectName] [nchar](50) NOT NULL,
[ClassHour] [int] NOT NULL,
[GradeId] [int] NOT NULL
)
GO
/*–案例:使用SQL语句创建Result结果表–*/
IF EXISTS(SELECT * FROM sysobjects WHERE name=’Result’)
DROP TABLE ResultResult
CREATE TABLE [dbo].[Result](
[StudentNo] [int] NOT NULL,
[SubjectNo] [int] NOT NULL,
[StudentResult] [int] NOT NULL,
[ExamDate] [datetime] NOT NULL
)
GO
/*–案例:使用SQL脚本创立Student学生表–*/
IF EXISTS(SELECT * FROM sysobjects WHERE name=’Student’)
DROP TABLE Student
CREATE TABLE [dbo].[Student](
[StudentNo] [int] NOT NULL,
[LoginPwd] [nvarchar](50) NOT NULL,
[StudentName] [nvarchar](50) NOT NULL,
[Sex] [bit] NOT NULL,
[GradeId] [int] NOT NULL,
[Phone] [varchar](50) NULL,
[Address] [nvarchar](255) NULL,
[BornDate] [datetime] NOT NULL,
[Email] [varchar](50) NULL,
[IdentityCard] [varchar](18) NOT NULL,
)
GO
/*–案例:使用SQL脚本创立Grade年级表–*/
IF EXISTS(SELECT * FROM sysobjects WHERE name=’Grade’)
DROP TABLE Grade
CREATE TABLE [dbo].[Grade](
[GradeId] [int] IDENTITY(1,1) NOT NULL,
[GradeName] [nvarchar](50) NOT NULL
)
GO
alter table Student
add Constraint pk_StudentNo primary key(StudentNo)
–Student表中的唯一约束
alter table Student
add Constraint uq_IdentityCard unique(IdentityCard)
–student表中的暗中认可约束
alter table Student
add Constraint df_Address default(‘地址不详’) for Address
–student表中的检查约束
alter table Student
add Constraint ck_BornDate check(BornDate>’1980-01-01′)
–外键约束
alter table Grade
add Constraint pk_GradeId PRIMARY key(GradeId)
alter table Student
add Constraint fk_Grade foreign key(GradeId)
references Grade(GradeId)
go
–向Subjiect添加封锁
alter table Subject
add Constraint pk_SubjectNo primary key(SubjectNo)
alter table Subject
add Constraint ck_ClassHour check(ClassHour>0)
ALTE陆风X8 TABLE Subject –非空约束(课程名称)
ADD CONSTRAINT CK_SubjectName CHECK (SubjectName is not null)
alter table subject
add Constraint fk_GradeId foreign key(GradeId)
references Grade(GradeId)
go
–使用SQL语句创立Result表的自律
ALTEOdyssey TABLE Result –主键约束(学号、科目号、日期)
ADD CONSTRAINT PK_Result PRIMARY KEY
(StudentNo, SubjectNo, ExamDate)

ALTEQashqai TABLE Result –默许约束(日期为系统当下日子)
ADD CONSTRAINT CK_ExamDate DEFAULT (getdate()) FOR ExamDate

ALTE昂科威 TABLE Result –检查约束(分数不能够超过十0,小于0)
ADD CONSTRAINT CK_StudentResult CHECK
(StudentResult BETWEEN 0 AND 100)

ALTELAND TABLE Result –外键约束(主表Student和从表Result建立关系)
ADD CONSTRAINT FK_StudentNo
FOREIGN KEY (StudentNo) REFERENCES Student (StudentNo)

ALTE本田UR-V TABLE Result –外键约束(主表Subject和从表Result建立关联)
ADD CONSTRAINT FK_SubjectNo
FOREIGN KEY (SubjectNo) REFERENCES Subject (SubjectNo)
GO


DATEDIFF(DY, BornDate, GETDATE())/365
DatePart()函数用于再次回到日期可能时间的独门部分,比如年、月、日、小时、分
例如 DatePart(YY,BornDate)
回来出生年月初的年份

能够通过DatePart()函数获得学号二零零三一的学员大三周岁和小贰周岁的上学的小孩子

declare @year datetime
select @year= BornDate from Student where StudentNo=20011
select StudentName,sex,datepart(YY,BornDate) as BornDate from Student
where StudentNo=20011 or datepart(YY,BornDate)= @year+1 or
datepart(YY,BornDate)=@year-1

–select * from Student where
ABS(DATEDIFF(DAY,@year,BornDate))/365<=1

–select * from Student where DATEDIFF(DAY,@year,BornDate)/365<=1
and DATEDIFF(DAY,BornDate,@year)/365<=1

–select * from Student

–子查询
总是用小括号括起来,先实施螺号里面包车型地铁子查询,然后才实施外围的父查询
–注意:将子查询和相比较运算符联合利用,必须保险子查询的归来结果为一个。
–查看比李思文小的学生
–declarre @date datetime
–select BornDate as ‘李斯文的出出生之日期’ from Student where
StudentName=’李Sven’
–select * from Student
–where BornDate > (select BornDate as ‘李Sven的出生日期’ from

Student where StudentName=’李斯文’)

高档查询
简单子查询的用法
declare @Birthday datetime
select @Birthday = BornDate from student where studentName=’李斯文’;
select studentName,sex from student where BornDate>@Birthday


select StudentResult from Result
where SubjectNo=(select SubjectNo from Subject where SubjectName=’C#
OOP’) and
ExamDate=(select max(ExamDate) from Result where SubjectNo=(select
SubjectNo from Subject where SubjectName=’C# OOP’))
–select max(ExamDate) from Result where SubjectNo=(select SubjectNo
from Subject where SubjectName=’C# OOP’)
–一.从课程名称查询出课程编号,贰.从课程编号查询出以来(大)日期,从一和2协同查询出考试战表。
–查询Java课程考试成绩为五二十分的学生名单–in
关键字:查询出来的结果可能是多个
select StudentName from Student where StudentNo in
(
select StudentNo from Result where SubjectNo=(select SubjectNo from
Subject where SubjectName=’Java Logic’)
and
StudentResult=60
)


–in 用法 查询结果有多少个
select StudentNo,studentName from Student where GradeId in (select

GradeId from Grade where GradeName = ‘S1’)

聚合函数:sum avg min max count(null列不总括在rpu内)
分组:select groupId,avg(age) from student
group by groupId
having avg(age)<=30 刷选
where 和 having的区分:where 对表中的原本数据开始展览帅选,
having对分组后选择聚合函数总括后的多寡进行帅选

having一般与group by结合使用

视图
视图名称
creatview view_name(view_colum_name)
As query_expression(查询表明式)

[with check option](添加封锁规范)

–分组查询 Group by 在select 语句询问的终极。

select studentResult ,sum(subjectNo) from Result group by
studentResult
–出现Group by 一般就会产出聚合函数
–查询学生每壹门学科的平均战表
–须要出示学生姓名,课程名称,
–科目ji的平分分–怎么样将studentNo与studentName联系在一块儿?
select SubjectNo , AVG(studentResult)From Result group by subjectNo
–left on student.
select SubjectName ,AVG(studentResult)from Result
left join subject on
subject.SubjectNO=result.subjectNo ///////left join 外表 on
俩表相等的字段
group by SubjectName –学生的平均分

–select studentNo ,AVG(studentResult) from Result where StudentNo=1000
group by studentNo
–查询课程的实际业绩 展现课程名称以及所对应的成就
–left join 左链接!!!! 主从表的关系左边的是主表 on
select SubjectNo , AVG(studentResult)From Result group by subjectNo
select Result.StudentResult,SubjectName from Result
Left join Subject on –left join +主表 on前边加俩个表相同的字段

subject.SubjectNO=result.subjectNo

事务 视图 索引
begin transaction
declare @error int
set @error=0
update bank set currentmoney=currentmoney-1000 where
customername=’张三’
set @error=@error+@@error 错误音讯 全局变量
update bank set currentmoney=currentmoney+1000 where
customername=’李四’
set @error=@error+@@error
给客户3个可视化的结果,
if(@error<>0)
begin
print ‘转账失败,重重新操作’
rollback transaction 回滚
end

esle
begin
print ‘转账成功张3给李4转了一千’
commit transaction 提交给数据库
end
go

一.事务逻辑供给三个T_SQL语句来推行

create table bank
(
customername varchar(5)
currentmoney int
)

作业属性:原子性(各样步骤无法再分,要么都履行,要么都不实施)
1致性 当事务实现时,数据必须处于相同状态
隔数离性 并发东西之间相互隔开分离,独立,不应重视其余
永久性
起来事务: begin transaction
交付业务:commit transaction
回滚事务:roollback transaction

事情是消除也许存在的难点

begin transaction
declare @error int
set @error=0
insert into Result values(113,2,150,GETDATE())
set @error=@error+@@error

if(@error<>0)
begin
print ‘插入失利’
rollback transaction
end

else
begin
print ‘插入成功’
commit transaction
end

select * from Result

目录:依照索引键查找定数据行
汉语字典中的汉字按“页”存放,壹般都有中文拼音的目录(索引),偏旁部首目录等
sql中的数据也是按页存放
目录;shi sql编排数据的章程

唯一索引,主键索引,聚集索引,

仓库储存进程
系统存款和储蓄过用程的名字一般以sp_开头
增添存款和储蓄1般xp

调用存款和储蓄
execute 过程名 [参数] 或者 exec 过程名 [参数]

create proc[edure] 存款和储蓄进度名
@参数1 数据类型=默许值 output
。。。。。。。
@参数n 数据类型=暗许值 output
as
sql语句
go

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图