Learning Mysql



Download 4.24 Mb.
View original pdf
Page162/366
Date04.08.2023
Size4.24 Mb.
#61806
1   ...   158   159   160   161   162   163   164   165   ...   366
Learning MySQL
180 | Chapter 6:
Working with Database Structures

but under Windows, this will normally work. To make your SQL machine-independ- ent, we recommend that you consistently use lowercase names for databases (and for tables, columns, aliases, and indexes).
There are other restrictions on database names. They can beat most 64 characters in length. You also shouldn’t use MySQL reserved words—such as SELECT, FROM, and
USE
—as names for structures these can confuse the MySQL parser, making it impossible to interpret the meaning of your statements. Theresa way around this problem you can enclose the reserved word with the backtick symbol (
‵) on either side, but it’s more trouble remembering to do so than it’s worth. In addition, you can’t use selected characters in the names specifically, you can’t use the forward slash, backward slash, semicolon, and period characters, and a database name can’t end in whitespace. Again, the use of these characters confuses the MySQL parser and can result in unpredictable behavior. For example, here’s what happens when you insert a semicolon into a database name:
mysql> CREATE DATABASE IF NOT EXISTS lu;cy;
Query OK, 1 row affected (0.00 sec)
ERROR 1064 (42000): You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'cy' at line Since more than one SQL statement can be on a single line, the result is that a database lu is created, and then an error is generated by the very short, unexpected SQL statement cy;
Creating Tables
This section covers topics on table structures. We show you how to Create tables, through introductory examples Choose names for tables and table-related structures Understand and choose column types Understand and choose keys and indexes Use the proprietary MySQL
AUTO_INCREMENT
feature
When you finish this section, you’ll have completed all of the basic material on creating database structures the remainder of this chapter covers the sample music database used in the book, and how to alter and remove existing structures.
Basics
For our examples in this section, we’ll assume that the database music hasn’t been created. If you want to follow the examples, and you have already loaded the database,
you can drop it for this section and reload it later dropping it removes the database,

Download 4.24 Mb.

Share with your friends:
1   ...   158   159   160   161   162   163   164   165   ...   366




The database is protected by copyright ©ininet.org 2024
send message

    Main page