数据库中的单引号双引号和符号的⽤法和区别
在sql语句中经常会⽤到单引号双引号和&,下⾯以insert语句为例,select,update,delete语句都是⼀样的
1.插⼊字符串型
插⼊名字为张红的⼈,是字符串,所以insert语句当中名字两边要加单引号
strsql=“insert into mytable(username) values('张红') ”
如果名字变成了⼀个变量 thename,语句要写成:
strsql=“insert into mytable(username) values('“ & thename & ”') ”注意所有的连接符前后需要有空格
如果插⼊的是两个字段:
strsql=“insert into mytable(username,type) values('张红',‘学⽣’) ”
strsql=“insert into mytable(username,type) values('“ & thename&”','“ & thetype & ”') ”
这时候插⼊了两个变量thename和thetype
2.插⼊数字型
插⼊数字型数据不⽤添加单引号
插⼊年龄18,语句:
strsql=“insert into mytable(age) values(18) ”
如果年龄变成⼀个the age的变量,
语句:strsql=“insert into mytable(age) values(“ & theage & ”) ” 这时候因为是数字所以不需要⽤单引号了
3.插⼊⽇期型数据,⽇期型数据和单引号类似,但是要将单引号换为#
Strsql="insert into mytabel (birthday) values (# 2019-5-2 #)"
将⽇期换为the table,strsql=“insert into mytable(birthday) values (#“ & thedate & ”#)”
4.插⼊布尔型,布尔型和数字类型类似,只不过是有两个值true 和false
strsql=“Insert into mytable(marry) values(True)”
如果换成布尔变量themarry
strsql=“Insert into mytable(birthday) values(“ & themarry &  ”)”
总结:字符串变量需要⽤单引号,数字和布尔型变量不需要单引号,⽇期需要⽤#,access数据库中⽤单引号也可以替换变量:要加双引号,双引号中间需要有连接符& &
sql中delete用法在敲学⽣的时候,会看到下⾯这样的语句:
txtsql = "select * from user_info where user_id='" & Username & "'"
在这⾥username就是⼀个变量需要⽤双引号和连接符&

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。