search
HomeDatabaseMysql TutorialComprehensive exposure to SQL syntax (1)

Comprehensive exposure to SQL syntax (1)

Dec 24, 2016 pm 05:44 PM
sql syntax

SQL functions and features
In fact, in the previous article, some basic functions of SQL commands have been mentioned. However, through SQL commands, programmers or database administrators (DBA) can:
(1) Create database tables . (Including setting the space that can be used by the table)
  (2) Change the database system environment settings.
  (3) Grant users access rights to a certain database or table.
  (4) Create index values ​​for database tables.
  (5) Modify the database table structure. (Create, delete or modify table fields)
  (6) Create new data in the database.
  (7) Delete data from the database.
  (8) Modify data in the database.
  (9) Query data from the database.
 These are the things that can be accomplished through SQL commands. Doesn’t it seem that there are many more functions than the word “query” represents?

 Classification of SQL syntax

In fact, there are not many SQL commands, but to use SQL to perfection, only a few commands are enough, because SQL commands are grammatical descriptions created for relational databases , so SQL plays a very powerful role in this type of database. The following will classify and introduce the basic SQL syntax commands commonly used in VB. Before explaining the commands and syntax of SQL, SQL is classified below. The types used in SQL syntax can be said to be included in these categories.

 The first category, attribute words (PRedicates)

 It is used in SQL commands to indicate the way to select the records. Such as ALL, TOP and DISTINCT, etc.

  The second category, Declaration

  Make declarations on the name and data type of SQL Parameter or Parameter Query, such as the declaration of PARAMETERS, etc.

 The third category, conditional clause (Clause)

 In SQL queries, some expressions are used to define the conditions of the query to narrow the scope of the search, such as WHERE.

 The fourth category, operator (Operator) and operand (Operation)

 In SQL query, it and Operation together form an expression (Expression), such as BETWEEN....AND operator and INNER JOIN operand.

 The fifth category, Function

  Some common SQL functions, such as AVG(), are functions that find the arithmetic mean.

  The sixth category, SQL statement (Statement)

  The SQL statement can be said to be the main body of SQL grammar. It is used to issue instructions to a specific database and return related data. The syntax structure of SQL is basically It can be represented by the following formula: command + conditional clause

For example:

SELECT*FROM TAB WHERE TAB.NAME='A'

"FROM....WHERE" is a condition Clause, in fact, the syntax of SQL is not difficult. You only need to remember such a rule, and I believe you can quickly understand the usage of SQL.

 SQL syntax and commands


SELECT statement
SELECT[predicate]{*|table.*|[table.]field [,[table.]field2[,...]]} [AS alias1 [,alias2[ ,...]]]
FROM tableexpression [,...][IN externaldatabase]
[WHERE...]
[GROUP BY...]
[HAVING...]
[ORDER BY...]
[WITH OWNERaccess OPTION]
The SELECT statement includes the following parts
predicate



As mentioned earlier, it includes ALL, DISTINCT, DISTINCTROW, and TOP. We can use such statements to limit the results obtained after the query.

  *

 Specify all fields from the specified table.

 table

 The name of the specified table for the fields of the selected records.

 field1,field2

  If the field name you want to read data contains more than one field, the data will be read in the order listed.

 alias1,alias2

  Pseudonyms used to replace the actual field names in the form.

 tableexpression

 Table name or table containing the data we want.

 Externaldatabase

 If a database other than the current one is used, define its name in externaldatabase.
 
  ALL, DISTINCT, DISTINCTROW, TOP attribute word usage

SELECT [ALL|DISTINCT|DISTINCTROW|[TOP n[PERCENT]]] FROM table

  ALL

If you do not specify any field data, the Microsoft Jet database The database engine will select all fields and query the required data set based on the specified conditions.

The above is the content of comprehensive contact with SQL syntax (1). For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MySQL BLOB : are there any limits?MySQL BLOB : are there any limits?May 08, 2025 am 12:22 AM

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

MySQL : What are the best tools to automate users creation?MySQL : What are the best tools to automate users creation?May 08, 2025 am 12:22 AM

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

MySQL: Can I search inside a blob?MySQL: Can I search inside a blob?May 08, 2025 am 12:20 AM

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc

MySQL String Data Types: A Comprehensive GuideMySQL String Data Types: A Comprehensive GuideMay 08, 2025 am 12:14 AM

MySQLoffersvariousstringdatatypes:1)CHARforfixed-lengthstrings,idealforconsistentlengthdatalikecountrycodes;2)VARCHARforvariable-lengthstrings,suitableforfieldslikenames;3)TEXTtypesforlargertext,goodforblogpostsbutcanimpactperformance;4)BINARYandVARB

Mastering MySQL BLOBs: A Step-by-Step TutorialMastering MySQL BLOBs: A Step-by-Step TutorialMay 08, 2025 am 12:01 AM

TomasterMySQLBLOBs,followthesesteps:1)ChoosetheappropriateBLOBtype(TINYBLOB,BLOB,MEDIUMBLOB,LONGBLOB)basedondatasize.2)InsertdatausingLOAD_FILEforefficiency.3)Storefilereferencesinsteadoffilestoimproveperformance.4)UseDUMPFILEtoretrieveandsaveBLOBsco

BLOB Data Type in MySQL: A Detailed Overview for DevelopersBLOB Data Type in MySQL: A Detailed Overview for DevelopersMay 07, 2025 pm 05:41 PM

BlobdatatypesinmysqlareusedforvoringLargebinarydatalikeImagesoraudio.1) Useblobtypes (tinyblobtolongblob) Basedondatasizeneeds. 2) Storeblobsin Perplate Petooptimize Performance.3) ConsidersxterNal Storage Forel Blob Romana DatabasesizerIndimprovebackupupe

How to Add Users to MySQL from the Command LineHow to Add Users to MySQL from the Command LineMay 07, 2025 pm 05:01 PM

ToadduserstoMySQLfromthecommandline,loginasroot,thenuseCREATEUSER'username'@'host'IDENTIFIEDBY'password';tocreateanewuser.GrantpermissionswithGRANTALLPRIVILEGESONdatabase.*TO'username'@'host';anduseFLUSHPRIVILEGES;toapplychanges.Alwaysusestrongpasswo

What Are the Different String Data Types in MySQL? A Detailed OverviewWhat Are the Different String Data Types in MySQL? A Detailed OverviewMay 07, 2025 pm 03:33 PM

MySQLofferseightstringdatatypes:CHAR,VARCHAR,BINARY,VARBINARY,BLOB,TEXT,ENUM,andSET.1)CHARisfixed-length,idealforconsistentdatalikecountrycodes.2)VARCHARisvariable-length,efficientforvaryingdatalikenames.3)BINARYandVARBINARYstorebinarydata,similartoC

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.