mysql应该使用撇号在mysql查询? [英] mysql should i use apostrophe in mysql queries?

查看:413
本文介绍了mysql应该使用撇号在mysql查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数值数据类型上向MySQL数据库写入查询的正确方法是:

What is the correct way of writing a query to a MySQL database on numeric data-types:

  SELECT * FROM accounts WHERE id = 5;

  SELECT * FROM accounts WHERE id = '5';

主要我喜欢最后一个,使用'

Mainly I prefer the last one, using ' because it is more consistent with text data-types.

推荐答案

方案

引用的是字符串,MySQL将读取这些引号,然后将其转换为一个整数,这是慢的,然后只是递给它一个int开始。

Quotes are for strings, MySQL is going to read those quotes and then cast it to an integer, this is slower then just handing it an int to begin with.

老实说,性能上的差异很小,但它就像编写一个程序,将数字存储在字符串中,然后在需要做一些数学运算时转换为int。这是不好的做法。

Honestly the performance difference is minor, but it is just like writing a program that stores numbers in strings and then casts to int when it needs to do some math. This is bad practice.

这篇关于mysql应该使用撇号在mysql查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆