How to change table structure in mysql

Page 1

How to Change Table Structure in MySQL How to change table structure in mysql - To change the structure of a table, the general form of its SQL command is as follows: ALTER TABLE table_name alter_options; Where :   

ALTER TABLE is the basic command to change the table. table_name is the name of the table to be changed its structure. alter_options is a table change option. Useable options, some of which are as follows:

» ADD new_field_definitions This option is used to add new fields with " new_field_definitions " (field names, types and other options). » ADD INDEX index_name This option is used to add an index with the name "index_name" in the table. » ADD PRIMARY KEY (field_key) Option to add a primary key to the table » CHANGE field_changed new_field_definitions Option to change field_changed to new_field_definitions » MODIFY field_definition The option to change a field into a field_definition » DROP field_names Option to delete field field_names » RENAME TO new_table_name Option to rename the table Some examples of ALTER command variations to change the structure of a table include: Previously read the first tutorial: How to Create Table in MySQL using CMD 1. Add a primary key to a table ALTER TABLE student ADD PRIMARY KEY(studentnumber);

2. Add the "religion" field to the student table ALTER TABLE student ADD religion varchar(15) NOT NULL;


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.
How to change table structure in mysql by Info Kita - Issuu