Creating and Dropping Tables
With MySQL or mSQL successfully installed, you should now be ready to create your first table. The table, a structured container of data, is the basic concept in a relational database. Before you can begin adding data to a table, you must define the table’s structure. Consider the following layout:
+---------------------------------+ | people | +-------------+-------------------+ | name | char(10) not null | | address | text(100) | | id | int | +-------------+-------------------+
Not only does the table contain the names of the columns, but it also contains the types of each field as well as any additional information the fields may have. A field’s datatype specified what kind of data the field can hold. SQL datatypes are similar to datatypes in other programming languages. The full SQL standard allows for a large range of datatypes. MySQL implements most of them, while mSQL contains only a few of the most useful types.
The general syntax for table creation is:
CREATE TABLEtable_name
(column_name1
type
[modifiers]
[
,column_name2
type
[modifiers]]
)
Note
What constitutes a valid identifier—a name for a table or column—varies from DBMS to DBMS. mSQL provides close to the bare minimum support for names. It accepts any sequence of International Standards Organization (ISO) 8859-1 (Latin 1) letters, numbers, or `_' up to 20 characters as a valid identifier. An identifier must begin with a letter. Good database design only encounters problems with the ISO 8859-1 ...
Get MySQL and mSQL now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.