SQL Syntax

 Let us first talk about the elements that make up the SQL grammar.

Database Tables

The most important object in the database is the table. The database is composed of one or more tables. The name of each table is unique in the database. Each row in the table (column) Call it a field. Each field has its data type. A row composed of different fields is called a record. Let’s take one called "customers" Data table as an example:

C_IdNameCityAddressPhone
1Zhang YiTaipei City100 XX Road02-12345678
2King TwoHsinchu County200 YY Road03-12345678

This data table contains 2 records and 5 fields (C_Id, Name, City, Address, Phone)

Table names are case-sensitive, but some databases are not case-sensitive in the Windows operating system, and it is better to unify your naming method for the convenience of maintenance.

SQL statements (Statements)

We use SQL statements to communicate with the database and issue instructions. The SQL language is composed of commands, clauses, operators and functions. Usually a SQL statement consists of a command The sentence begins to describe the action you want to require on the database, and then may be followed by a conditional sentence, and finally ends with a semicolon ";":

Some databases do not require a semicolon at the end.
SELECT * FROM customer;

The SQL statement above means to retrieve all data from the customer data table.

SQL statements are not case sensitive (case-insensitive), such as select * from customer;and the examples are the same results.

What are commands (Commands)

Create new databases, data tables, fields, indexes, etc., or create query tables, sort, filter data, query, modify, add, and delete data. (I.e. CREATE, DROP, ALTER, SELECT, INSERT, UPDATE, DELETE and other commands)

What is a clause (Clauses)

Clause is used to set and operate your SQL query, for example:

ClauseDescription
FROMSpecified table
WHERESet query conditions
GROUP BYSet grouping conditions
ORDER BYSet output order

What are operators

Operators are used to help SQL statements process numeric values, strings, or perform logical operations and comparison conditions.

What are functions

Many built-in functions of the SQL language can be used directly in SQL statements, such as obtaining the total value of a field, obtaining the maximum or minimum value in a field, and so on.

SQL statement writing habits

Capitalizing the SQL keywords in all executed statements is a good SQL writing habit, which will help you to view your SQL syntax more easily.

In addition, you can split long SQL statements into multiple lines for writing, which will make it easier for you to read!

SELECT column_one, column_two
FROM table_name
WHERE table_id = 123;

Post a Comment

0 Comments