in previous posts we have created a database with the name becoding that contains a table with namefriend that which has the following structure:
ScreenShot: Structure [Click Here]
if you do not have a database of over please read his tutorial part 2
1.Change / Modify (used to change the field).
2.Add column (used to add field).
3.Drop column (used to delete the field).
1.Change / Modify
Now we will start by modifying a field with two kinds of commands that 'change' and 'modify'.then what is the difference between these two commands, the difference is the change used to change a field from the name to the data type, whereas modify only be used to change the data type of a field.
how writing is:
Change: change old_field_name new_field_name new_data_type;
Modify: modify field_name new_data_type;
for example we want to change the size of the field name that was originally 12 to 30, then the command used is'Alter table friend modify name char (30) not null;', used modify because we only want to change field size.
ScreenShot: Modify [Click Here]
ScreenShot: Change [Click Here]
2.Add column
We've learned how to modify the field now we will learn how to add a new field to a certain table.with the command 'add column'.
writing is 'add column field_name data_type;'
for example, we will add a new column with the names 'grade' data type char size 1 into table 'friend', then the writing is'Alter table friend add column grade char (1) not null;'
ScreenShot: Add Column [Click Here]
3.Drop column
Next we will learn to remove a field from a table with a drop column command,writing is 'drop column field_name;'.
for example, we will remove Grade field from the table friend the , then the writing is'Alter table friend drop column grade;'.
ScreenShot: Drop Column [Click Here]
That some commands to modify the next field we will continue with the command alter the other, i hope this post can be useful for you all. Our BeCoding.tk thank you for visiting and reading to the end.
Tidak ada komentar:
Posting Komentar