13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

262 Chapter 10 Working with Your <strong>MySQL</strong> Database<br />

The different types of alterations you can make with this statement are shown in<br />

Table 10.5.<br />

Table 10.5 Possible Changes with the ALTER TABLE Statement<br />

Syntax<br />

Description<br />

ADD [COLUMN] column_description Adds a new column in the specified location<br />

[FIRST | AFTER column ]<br />

(if not specified, then the column goes at the<br />

end). Note that column_descriptions<br />

need a name <strong>and</strong> a type, just as in a CREATE<br />

statement.<br />

ADD [COLUMN] (column_description, Adds one or more new columns at the end<br />

column_description,...)<br />

of the table.<br />

ADD INDEX [index] (column,...) Adds an index to the table on the specified<br />

column or columns.<br />

ADD [CONSTRAINT [symbol]]<br />

Makes the specified column or columns the<br />

PRIMARY KEY (column,...)<br />

primary key of the table.The CONSTRAINT<br />

notation is for tables using foreign keys. See<br />

Chapter 13”Advanced <strong>MySQL</strong> programming,”for<br />

more details.<br />

ADD UNIQUE [CONSTRAINT [symbol]] Adds a unique index to the table on the<br />

[index] (column,...)<br />

specified column or columns.The<br />

CONSTRAINT notation is for InnoDB tables<br />

using foreign keys. See Chapter 13 for more<br />

details.<br />

ADD [CONSTRAINT [symbol]]<br />

Adds a foreign key to an InnoDB table.<br />

FOREIGN KEY [index] (index_col,...) See Chapter 13 for more details.<br />

[reference_definition]<br />

ALTER [COLUMN] column {SET DEFAULT Adds or removes a default value for a<br />

value | DROP DEFAULT}<br />

particular column.<br />

CHANGE [COLUMN] column new_column Changes the column called column so that it<br />

description<br />

has the description listed. Note that this syntax<br />

can be used to change the name of a column<br />

because a column_description<br />

includes a name.<br />

MODIFY [COLUMN] column_description Similar to CHANGE. Can be used to change<br />

column types, not names.<br />

DROP [COLUMN] column<br />

Deletes the named column.<br />

DROP PRIMARY KEY<br />

Deletes the primary index (but not the<br />

column).<br />

DROP INDEX index<br />

Deletes the named index.<br />

DROP FOREIGN KEY key<br />

Deletes the foreign key (but not the<br />

column).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!