Changing Structure Table with ALTER
How to Changing Structure Table With ALTER on SQL
To change the structure of a table, form its common SQL commands as follows:
ALTER TABLE table_name alter_options;
explanation:
ALTER TABLE constitute basic commands for changing tables.
table_name the name of the table modified structure.
alter_options a changing selection table. Option that can be used, some in including the following:
ADD definisi_field_baru
This option is used to add field new
Definisi_field_baru" (field names, types and options
other).
ADD INDEX index_name This option is used to add index with the name "index_name" on the table.
ADD PRIMARY KEY (field_kunci) Option to add a primary key in the table
CHANGE field_yang_diubah definisi_field_baru Option to change field_yang_diubah be definisi_field_baru
MODIFY definisi_field Option to convert a field into definisi_field
DROP name_field Option to remove the field nama_field
RENAME TO nama_tabel_baru Option to change the name of the table
Variations command ALTER
ALTER TABLE ADD religion MHS varchar (15) NOT NULL;
Adding a primary key on a table
MHS ALTER TABLE ADD PRIMARY KEY (NIM);
Changing the religion field length to 10 characters in the table MHS
ALTER TABLE CHANGE MHS religions varchar (10);
No comments