Database Reference
In-Depth Information
SQL allow you to issue the command CREATE OR REPLACE when you are creating a table,
which will replace the existing table if needed. MySQL does not yet support this function.
You will notice that the line:
TYPE = InnoDB
has been added at the end of the table definition. This is the table type that you need to
use if you want MySQL to support referential integrity.
Create from Select Statement
You can also create tables based on the output of a select statement. The format is as follows:
CREATE TABLE tablename AS selectstatement
We will describe the select statement in detail in a later chapter. The select statement
allows you to select some or all of the column and rows in a table. For instance, if we
decided that we wanted to make a different log table with all of the client details removed,
we could do it with the following script:
CREATE TABLE Log2 AS SELECT ID,
CookieID,
WebpageID,
DateCreated,
Referringpage
FROM log
The select statement that we use here requests those column names that do not contain
client details. After creating this table, describing it gives the results shown in Figure 4.11.
Compare Figure 4.11 with Figure 4.9. You will notice that the new table has fewer
columns, as we expected. The new table has been created purely from the column names
and datatypes of the select statement, and took no notice of the other column options our
Figure 4.11
DESCRIBE Log2 table.
Search WWH ::




Custom Search