sql常见语法

SQL Server Management Studio, errors can be tracked down easily, using the built in 错误列表”窗格,可以轻松跟踪Error List pane. This pane can be activated in the SQL Server Management Studio错误。 可以在“ View menu, or by using shortcuts 视图”菜单中或使用快捷键Ctrl+\ and Ctrl + \Ctrl+E Ctrl + E激活此窗格。

The Error List pane displays syntax and semantic errors found in the query editor. To navigate directly to the SQL syntax error in the script editor, double-click the corresponding error displayed in the Error List

“错误列表”窗格显示在查询编辑器中发现的语法和语义错误。 要在脚本编辑器中直接导航到SQL语法错误,请双击“错误列表”中显示的相应错误。

SQL关键字错误 (SQL Keyword errors)

SQL keyword errors occur when one of the words that the SQL query language reserves for its commands and clauses is misspelled. For example, writing “UPDTE” instead of “UPDATE” will produce this type of error

当SQL查询语言为其命令和子句保留的单词之一拼写错误时,就会发生SQL关键字错误。 例如,写“ UPDTE”而不是“ UPDATE”将产生这种类型的错误。

In this example, the keyword “TABLE” is misspelled:

在此示例中,关键字“ TABLE”的拼写错误:

As shown in the image above, not only the word “TBLE” is highlighted, but also the words around it. The image below shows that this simple mistake causes many highlighted words

如上图所示,不仅单词“ TBLE”突出显示,而且周围的单词也突出显示。 下图显示此简单错误导致许多突出显示的单词

In fact, there are total of 49 errors reported just because one keyword is misspelled

实际上,仅由于一个关键字拼写错误,总共报告了49个错误

If the user wants to resolve all these reported errors, without finding the original one, what started as a simple typo, becomes a much bigger problem

如果用户想解决所有这些报告的错误,而又找不到原始错误,那么从一个简单的错字开始就变成了一个更大的问题。

It’s also possible that all SQL keywords are spelled correctly, but their arrangement is not in the correct order. For example, the statement “FROM Table_1 SELECT *” will report an SQL syntax error

所有SQL关键字的拼写也可能正确,但是它们的排列顺序不正确。 例如,语句“ FROM Table_1 SELECT *”将报告SQL语法错误

命令安排 (Arrangement of commands)

The wrong arrangement of keywords will certainly cause an error, but wrongly arranged commands may also be an issue

关键字排列错误肯定会导致错误,但是命令排列错误也可能是一个问题

If the user, for example, is trying to create a new schema into an existing database, but first wants to check if there is already a schema with the same name, he would write the following command

例如,如果用户试图在现有数据库中创建新模式,但是首先要检查是否已经存在一个具有相同名称的模式,则他将编写以下命令

However, even though each command is properly written, and is able to run separately without errors, in this form it results in an error

但是,即使正确地编写了每个命令,并且能够独立运行且没有错误,以这种形式也会导致错误

As the error message states, CREATE SCHEMA command has to be the first command that is given. The correct way of running this commands together looks like this

如错误消息所述,CREATE SCHEMA命令必须是给出的第一个命令。 一起运行此命令的正确方法如下所示

使用引号 (Using quotation marks)

Another common error that occurs when writing SQL project is to use double quotation marks instead of single ones. Single quotation marks are used to delimit strings. For example, double quotation marks are used here instead of single ones, which cause an error

编写SQL项目时发生的另一个常见错误是使用双引号而不是单引号。 单引号用于分隔字符串。 例如,此处使用双引号而不是单引号,这会导致错误

Replacing quotation marks with the proper ones, resolves the error

用正确的引号替换引号可以解决错误

There are situations where double quotation marks need to be used, for writing some general quotes, for example

在某些情况下,需要使用双引号来编写一些通用引号,例如

As shown in the previous example, this will cause an error. But, this doesn’t mean that double quotes can’t be used, they just have to be inside the single quotes. However, adding single quotes in this example won’t solve the problem, but it will cause another one

如上例所示,这将导致错误。 但是,这并不意味着不能使用双引号,而只需要在单引号内即可。 但是,在此示例中添加单引号不会解决问题,但会导致另一个问题

Since there is an apostrophe inside this quote, it is mistakenly used as the end of a string. Everything beyond is considered to be an error

由于此引号内有撇号,因此将其错误地用作字符串的结尾。 超出范围的所有内容均视为错误

To be able to use an apostrophe inside a string, it has to be “escaped”, so that it is not considered as a string delimiter. To “escape” an apostrophe, another apostrophe has to be used next to it, as it is shown below

为了能够在字符串中使用撇号,必须对其进行“转义”,以便不将其视为字符串定界符。 要“转义”一个撇号,必须在其旁边使用另一个撇号,如下所示

查找SQL语法错误 (Finding SQL syntax errors)

Finding SQL syntax errors can be complicated, but there are some tips on how to make it a bit easier. Using the aforementioned Error List helps in a great way. It allows the user to check for errors while still writing the project, and avoid later searching through thousands lines of code

查找SQL语法错误可能很复杂,但是有一些技巧使它变得更简单。 使用上述错误列表有很大帮助。 它允许用户在仍然编写项目的同时检查错误,并避免以后搜索数千行代码

Another way to help, is to properly format the code

另一种帮助方法是正确格式化代码

This can improve code readability, thus making the search for errors easier

这样可以提高代码的可读性,从而使错误查找更加容易

翻译自: https://www.sqlshack.com/sql-syntax-errors/

sql常见语法

sql常见语法_常见SQL语法错误以及解决方法相关推荐

  1. 开机启动失败_电脑常见开机引导错误的解决方法

    电脑在开机启动过程中,经常会出现开机失败的故障,开机失败比较常出现在开机引导项错误的问题上,比如引导文件没了,硬盘有问题等等,有些小问题重启几遍可以解决,有些问题就只能修复.这边小编跟大家整理分享几个 ...

  2. mysql转储导入错误_数据库MYSQL导入SQL文件时错误的解决方法(2种)

    从服务器数据库用navicate导出的.sql文件后再用navicate导入到本地的数据库中会出现若干条记录的错误: [Err] 1064 – You have an error in your SQ ...

  3. 遇到一个php的错误,php初学者常见的几个错误及解决方法

    本文为大家分享了php初学者常见的几个错误及解决方法,希望能够帮助到那些刚刚学习php的小伙伴们. 错误一:Parse error: syntax error, unexpected - 这种错误是P ...

  4. 常见的数据库错误的解决方法!必看!(含安装插件常见错误)

    这里所说的是MySQL Query Error提示错误的解决方法,部分是完全可以自己动手解决的,没有多大必要一遍遍问.除非是常规方法不能解决的~ 下面是常见安装插件会出现的数据库错误信息提示: [Co ...

  5. MySQL数据库常见错误与解决方法总结

    一.Can't connect to MySQL server on 'localhost' (10061) 翻译:不能连接到 localhost 上的mysql 分析:这说明"localh ...

  6. 局域网中最常见的十大错误及解决方法

    局域网中最常见的十大错误及解决方法 网络故障是在所难免的,重要的是应快速隔离和排除故障.网络维护人员应该配备相应的工具和相应的知识,以便及时.有效的找到和解决问题.本文讨论了网络技术人员和工程师经常遇 ...

  7. firebird数据库安装连接的一些常见错误及解决方法

    firebird数据库安装连接的一些常见错误及解决方法 最近有一个需求是把数据库里面的数据提取出来,这个数据库的后缀是.fdb,查阅资料可知应该是firebird数据库的文件,可是firebird数据 ...

  8. MySQL的配置方法以及数据库配置常见错误及其解决方法

    第一部分.MySQL的配置方法: 以下为笔者整理的mysql 5.5 安装配置教程笔记.通过逐一界面分析,解决大家在配置MySQL数据库时可能存在的疑惑. 首先给出MySQL下载地址:MySQL :: ...

  9. 稳定性专题 | Spring Boot 常见错误及解决方法

    导读 『StabilityGuide』是阿里多位阿里技术工程师共同发起的稳定性领域的知识库开源项目,涵盖性能压测.故障演练.JVM.应用容器.服务框架.流量调度.监控.诊断等多个技术领域,以更结构化的 ...

  10. SQL Server 2005 连接本地端口1433开启远程连接/登陆18456错误的解决方法

    SQL Server 2005 连接本地端口1433开启远程连接/登陆18456错误的解决方法 出处:http://jimmyli.blog.51cto.com/我站在巨人肩膀上Jimmy Li 作者 ...

最新文章

  1. spring boot 批量更新数据
  2. lintcode:删除链表中指定元素
  3. 【入门】WebRTC知识点概览 | 内有技术干货免费下载
  4. Python深度剖析贪吃蛇游戏的设计与实现
  5. SQL2008安装出现问题invoke---beginInvoke
  6. 2016 Bird Cup ICPC7th@ahstu--“波导杯”安徽科技学院第七届程序设计大赛
  7. sed的选项与命令简要
  8. 3 Git服务器搭建
  9. (转)让页面自动滚动到刷新页面之前的控件处,减少页面刷新带来的不便。
  10. Linux设置小红点键盘,让Ubuntu完美支持Thinkpad小红点Trackpoint
  11. 菲尼克斯电气——基于Proficloud的设备远程运维工业物联网解决方案
  12. veu中高德怎么定义多个marker?
  13. oracle 将钱转换万元单位,oracle 金额单位转换
  14. vue使用talkIngData统计
  15. 2020湖南省技能竞赛获奖名单_2020年全国职业院校技能大赛教学能力比赛落幕 湖南获一等奖数量排全国第一...
  16. 投资学 U15 利率期限结构 习题解读
  17. 从幂律分布到特征数据概率分布——12个常用概率分布
  18. Tcp/ip协议 详解
  19. AR单片机编程软件的菜单栏功能及用法
  20. Fan996餐饮外卖平台小程序 V1.0.1正式版

热门文章

  1. Android webm转mp4,Android中直接播放webm的视频an – 手机爱问
  2. ItemCreated和ItemDataBound事件的区别
  3. 赛效:WPS如何在文档中插入下一页分节符
  4. 微软飞行模拟器android,微软飞行模拟器
  5. Oday安全 12.3.1Ret2Libc实战之利用ZwSetInformationProcess一节注记(上)
  6. 使用unity开发答题系统
  7. [适合非python新手]selenium自动化测试 25-测试用例运行和报告
  8. kb2919355 此更新不适用于你的计算机的解决方法
  9. 基于matlab的巴特沃斯滤波器设计
  10. 关于前嗅Forespider爬虫的常见问题答疑