![]() ![]() The syntax of modifying the column is similar to adding the column which is as follows – We can modify the column by changing its definition and position by using the ALTER TABLE statement with MODIFY command. ALTER TABLE statement with MODIFY command The default value of integer datatype column is 0, varchar i.e string is “” blank and for date is NULL. Let us now, retrieve the records from developers table to view our changes by executing following select query –Īs we can see all the new columns are added at their respective positions that we mentioned and are initialized to its default value depending on their datatype. We can do so, by executing the following ALTER TABLE command – ![]() Suppose, we want to add three more columns named joiningDate, age, and address. We can even add multiple columns in single query statement. Note: That the value of the newly added experience column is set to 0 as we have mentioned it in the column definition. For this we can make the use of ALTER TABLE statement with ADD command and the query will be somewhat like this – Now, we need to add one more column named experience which is of integer datatype as it will store value in years. After executing the following SELECT command – Let us consider an existing table named developers. The default position where the new column is added is at the last. FIRST represents that the new column will be placed in the beginning while AFTER signifies the position of the new column after name_of_existing_column named column in the table. name_of_existing_column: We can specify the position of the column which we are adding with respect to the existing position of the columns in the table named name_of_table by using the FIRST and AFTER keywords.details_of_column: This helps to specify the details and definition of the new column we are adding that includes the datatype of the column and other details such as NULL or NOT NULL, UNIQUE, etc. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |