The SQL is very flexible when it comes to names. In
fact, it is very less restrictive than C++. Still, there are rules you
must follow when naming the objects in your databases:
- A name can start with either a letter (a, b, c, d, e, f, g, h, i, j,
k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G,
H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, or Z), a digit
(0, 1, 2, 3, 4, 5, 6, 7, 8, or 9), an underscore (_) or a non-readable
character. Examples are _n, act, %783, Second
- After the first character (letter, digit, underscore, or symbol),
the name can have combinations of underscores, letters, digits, or
symbols. Examples are _n24, act_52_t
- A name cannot include space, that is, empty characters. If you want
to use a name that is made of various words, start the name with an
opening square bracket and end it with a closing square bracket.
Example are [Full Name] or [Date of Birth]
Because of the flexibility of SQL, it can be difficult
to maintain names in a database. Based on this, there are conventions we
will use for our objects. In fact, we will adopt the rules used in C/C++,
C#, Pascal, Java, and Visual Basic, etc. In our databases:
- A name will start with either a letter (a, b, c, d, e, f, g, h, i,
j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F,
G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, or Z) or an
underscore
- After the first character, we can use any combination of letters,
digits, or underscores
- A name will not start with two underscores
- A name will not include one or more empty spaces. That is, a name
will be made in one word
- If the name is a combination of words, at least the second word will
start in uppercase. Examples are dateHired, _RealSport, FullName, or
DriversLicenseNumber
The command to create a database in SQL uses the
following formula:
CREATE DATABASE DatabaseName
The CREATE DATABASE (remember that SQL is not
case-sensitive, even when you include it in a C++ statement) expression is
required.
The DatabaseName factor is the name that the new database
will carry. Although SQL is not case-sensitive, as a C++ programmer, you
should make it a habit to be aware of the cases you use to name your
objects.
As done in C#, every statement in SQL can be
terminated with a semi-colon. Based on this, the above formula would be:
CREATE DATABASE DatabaseName;
To create a database with code, simply pass a CREATE
DATABASE statement (including the name of the database) to a MySqlCommand
object.
|
|