学习sql注入:猜测数据库_学习SQL:SQL数据类型
学习sql注入:猜测数据库
What are SQL data types, why do we need them, and how to use them? Today, we’ll try to answer these questions by giving an overview of some most common data types used in SQL Server.
什么是SQL数据类型?为什么需要它们?如何使用它们? 今天,我们将通过概述SQL Server中使用的一些最常见的数据类型来尝试回答这些问题。
该模型 (The Model)
Before doing anything else, we’ll take one quick look at the model we’re using in this series.
在做其他事情之前,我们将快速浏览一下本系列中使用的模型。
You can notice that each table has columns defined by their name, but also with their type. While the name is pretty obvious, and we’re the one defining it, the thing is little different when it comes to types. We can choose a column type from a list of predefined types or our custom type (again build from predefined types).
您会注意到,每个表都有由其名称和类型定义的列。 虽然名称很明显,而且我们是一个定义它的人,但是在类型方面却几乎没有什么不同。 我们可以从预定义类型或自定义类型的列表中选择列类型(同样从预定义类型构建)。
SQL数据类型–快速介绍 (SQL Data Types – Quick Intro)
Talking about data types is not the hottest thing in programming. They are just one of these things that are here, and we expect it to work. Still, it’s necessary to understand what we have at disposal.
谈论数据类型并不是编程中最热门的事情。 它们只是这里的其中之一,我们希望它能起作用。 尽管如此,还是有必要了解我们所拥有的。
When we’re storing data, we need to simulate “measures & formats” used in the real world. E.g. we want to store height as a decimal number, birth date as a date, ‘this sentence’ as a text, etc. You could always go with an extreme and store everything as text or photo.
当我们存储数据时,我们需要模拟现实世界中使用的“度量和格式”。 例如,我们要将身高存储为十进制数字,将出生日期存储为日期,将“此句子”存储为文本,等等。您总是可以选择极端,将所有内容存储为文本或图片。
Since databases are meant to store data and work with them efficiently, we won’t do that. We’ll have several different SQL data types at our disposal. We won’t only have types to store text or number, but we’ll also go deeper, with types closely describing the nature of that text (how long is it) or number (is it integer or decimal).
由于数据库旨在存储数据并有效地使用它们,因此我们不会这样做。 我们将使用几种不同SQL数据类型。 我们不仅将具有用于存储文本或数字的类型,而且还将更深入地介绍类型,这些类型紧密描述了文本的性质(多长时间)或数字(整数或十进制)。
The main idea behind data types is to simulate the most common types from the real-world. By doing so, the DBMS (database management system), will be able to store them efficiently (less space used, better organized), and that will also lead to improved performance.
数据类型背后的主要思想是模拟现实世界中最常见的类型。 这样,DBMS(数据库管理系统)将能够有效地存储它们(使用的空间更少,组织得更好),并且还可以提高性能。
These types vary between different DBMSs (SQL Server, MySQL, Oracle), but most of them are very similar. We’ll focus on the most important SQL Server/Transact-SQL data types.
这些类型在不同的DBMS(SQL Server,MySQL,Oracle)之间有所不同,但是大多数都非常相似。 我们将重点介绍最重要SQL Server / Transact-SQL数据类型。
文字数据类型 (Textual Data Types)
As you could see in our model, there are 3 most common types of real-world data we need to store: texts, numbers, and dates. Therefore, most DBMS (and programming languages) will support these 3 main groups. In each of these groups, you’ll find more or less standardized SQL data types.
正如您在模型中看到的那样,我们需要存储3种最常见的现实世界数据类型:文本,数字和日期。 因此,大多数DBMS(和编程语言)将支持这3个主要组。 在每个组中,您都会找到或多或少的标准化SQL数据类型。
So, let’s quickly review textual data types first. In the table below, you’ll find Transact-SQL string/textual data types with short descriptions.
因此,让我们首先快速查看文本数据类型。 在下表中,您将找到带有简短说明的Transact-SQL字符串/文本数据类型。
The most important are:
最重要的是:
- char(n) – where n is replaced by the maximum number of characters we expect in any string. If that number is exceeded, we won’t be able to store the complete string. E.g. char(8) means that we’ll store 8 characters. If the string has less than that, the remaining characters shall be filled with blanks. Therefore, char(n), always has the same length, uses static memory allocation, and works 50% faster than varchar(n) (in an ideal scenario). It’s wise to use char(n) when you’re completely sure about the length of the data you’ll store, e.g. postal codes, account numbers, phone numbers, bank codes, etc. char(n)–其中n被我们期望在任何字符串中的最大字符数替换。 如果超过该数字,我们将无法存储完整的字符串。 例如char(8)表示我们将存储8个字符。 如果字符串少于该数字,则其余字符应用空格填充。 因此,char(n)始终具有相同的长度,使用静态内存分配,并且比varchar(n)快50%(在理想情况下)。 当您完全确定要存储的数据长度(例如邮政编码,帐号,电话号码,银行代码等)时,最好使用char(n)。
- varchar(n) – serves the same purpose as char(n), but the difference here is that the string ends after the last character – we don’t add blanks to use the whole string. E.g. if you use varchar(255) and fill on 15 characters, then only 15 characters are stored. The problem here is that we don’t know the exact length of each string, so everything works slower (still, nothing critical). So, we’ve traded better performance in order to save some disk space varchar(n)–具有与char(n)相同的目的,但是区别在于字符串在最后一个字符之后结束–我们不添加空格来使用整个字符串。 例如,如果您使用varchar(255)并填写15个字符,则仅存储15个字符。 这里的问题是我们不知道每个字符串的确切长度,因此一切工作都较慢(仍然,没有关键要求)。 因此,为了节省一些磁盘空间,我们进行了更好的性能交换
- text – well, if you want to store an immense text, you should use this one
学习sql注入:猜测数据库_学习SQL:SQL数据类型相关推荐
- 学习sql注入:猜测数据库_学习SQL:删除和更新数据SQL最佳实践
学习sql注入:猜测数据库 Deleting and updating data is very common, but if performed without taking care, which ...
- 学习sql注入:猜测数据库_面向数据科学家SQL:学习简单方法
学习sql注入:猜测数据库 We don't pick a hammer and look for nails - that would be an unusual way of solving pr ...
- 学习sql注入:猜测数据库_对于SQL的热爱:为什么要学习它以及它将如何帮助您...
学习sql注入:猜测数据库 I recently read a great article by the esteemed @craigkerstiens describing why he feel ...
- mysql中10049是什么错误_【学习笔记】Oracle数据库10049用于分析SQL解析笔记案例
[学习笔记]Oracle数据库10049用于分析SQL解析笔记案例 时间:2016-11-05 13:54 来源:Oracle研究中心 作者:HTZ 点击: 次 天萃荷净 Oracle研究 ...
- mysql sql注入怎么获取数据_手把手教你通过SQL注入盗取数据库信息
目录数据库结构 注入示例判断共有多少字段 判断字段的显示位置 显示登录用户和数据库名 获取所有数据库名 获取对应数据库的表 获取对应表的字段 获取所有的用户密码 我们都是善良的银!一生戎码只为行侠仗义 ...
- php mysql 注入一句话木马_渗透技术--SQL注入写一句话木马原理
讲一下SQL注入中写一句话拿webshell的原理,主要使用的是 SELECT ... INTO OUTFILE 这个语句,下面是一个语句的例子: SELECT * INTO OUTFILE 'C:\ ...
- php如何防sql注入,如何在PHP中防止SQL注入
本篇文章将给大家介绍关于PHP中的SQL注入以及使用PHP-MySQLi和PHP-PDO驱动程序防止SQL注入的方法.下面我们来看具体的内容. 简单的SQL注入示例 例如,A有一个银行网站.已为银行客 ...
- SQL注入是什么,怎么防止SQL注入?
SQL注入是什么,怎么防止SQL注入? 一.什么是SQL注入? SQL注入是比较常见的网络攻击方式之一,它不是利用操作系统的BUG来实现攻击,而是针对程序员编程时的疏忽,通过SQL语句,实现无帐号登录 ...
- php pdo sql注入,PHP PDO是如何防止SQL注入的?
SQL注入是一个常见的问题,当一个新的或没有经验的开发人员编写的代码很容易受到攻击.PHP是最容易访问的编程语言之一,但是这常常导致不安全的代码或不好的实践. PDO (PHP数据对象)是一个数据库抽 ...
最新文章
- 挑战“IT我最大 Win7由你秀”
- 完美解决Linux服务器tomcat开机自启动问题
- system diagnostics starts什么意思_System类
- CS中常用转义符与@符号的作用
- 关于调用 Angular 属性指令 attribute Directive 是否需要带中括号的问题
- android重要的对象
- jFinal 2.2入门学习之一:搭建框架输出helloword
- 人力资源管理(HR)专业书籍推荐
- 数据挖掘导论(一):数据挖掘的定义,方法,用途
- 逻辑卷管理(LVM)
- Apollo学习笔记(一):canbus模块与车辆底盘之间的CAN数据传输过程
- CLOCs: Camera-LiDAR Object Candidates Fusion for 3D Object Detection(论文阅读笔记)
- php implode(),php implode函数怎么用
- eclipse新建JSP页面报错:Multiple annotations found at this line解决方法
- 华为鸿蒙系统失败,世界首富很无奈,第三大手机系统失败,华为鸿蒙会成功吗...
- 常用函数式接口及Stream流
- java根据提供word模板导出word文档
- C++STL开发温习与总结(六): 6.C++语言输入/输出流定义之输入/输出格式控制
- python3封装微信分账功能
- 怎么用python画指北针?
热门文章
- Python机器学习(Sebastian著 ) 学习笔记——第五章通过降维压缩数据(Windows Spyder Python 3.6)...
- 一个好的桌面图标的网站
- 数据库读现象和隔离级别
- Codevs 3342 绿色通道
- android上实现0.5px线条
- http statusCode 500状态码
- 作业帮电脑版在线使用_应届生应聘作业帮的在线辅导老师
- 生物特征验证是什么意思
- 不合群的人,经常习惯一个人独来独往,这样的人有出息吗?
- 焦虑症患者,整天心神不宁,忧心忡忡怎么办?
- 学习sql注入:猜测数据库_学习SQL:删除和更新数据SQL最佳实践