sql - syntax - (speaking sql)
In previous chapter i have explained How To Use Data types In SQL now i am gonna eplain you What is Syntax In SQL
Executing SQL commands that do not have proper syntax and formatting will result in a syntax error. Syntax errors might be the most common and first error messages new SQL developers will experience.
Let's now take a look at a very simple SQL command that will be used in just about every example contained in this tutorial from here on out.
Sample SQL Command:
use mydatabase;
This command identifies a database as a target database, meaning that any SQL command or query executed after this line will be run against the identified database. In this case, the database 'mydatabase' will be the target database. This is a good way to prevent mistakes and avoid potential data loss and a good reason to include this command into each and every authored SQL query.
sql - syntax: capitalization and spacing
In some programming languages, capitalizing commands or excessive spacing may or may not cause syntax code errors and cause the command to fail. SQL syntax is very loose when it comes to capitalization and spacing, allowing a lot of room for the developer to decide on his/her own preference in regards to capitalization and spacing.
Let's rewrite the same SQL command from the previous example and take advantage of SQL's loose syntax characteristics.
Sample SQL Command:
USE
mydatabase;
The example above, though it does look different due to the capitalization and spacing, will yield the same results as the first example.
sql - syntax: building good habits
While coding in any language, it is important to develop good, consistent habits and maintain clean code. Clean code allows another SQL developer to step right in where you have left off without missing a beat. A developer with diligent coding habits will prevent many syntax errors before executing his/her scripts and also will be able to detect possibly syntax problems before they cause problems in a SQL Command.
Good habits include:
- Consitency
- Clean and Concise
- Use of Comments (more on this later)
- Scalability
Coding in any language is as much of an art form as authoring best selling novels and stories. Take pride in doing so and always do your best to follow good coding habits.
No comments:
Post a Comment