Friday, 2 November 2012

MySQL: How to add column to existing table


To add column in existing table, you may refer to the 2 examples below:-


Example I: Add new varchar column to the end of the table
ALTER TABLE `tablename_here` ADD `new_column_name` VARCHAR( 255 ) NOT NULL ;

Example II: Add new integer column after an existing column in table
ALTER TABLE `tablename_here` ADD `new_column_name` INT NOT NULL AFTER `existing_column` ;


MySQL tables are easy to extend with additional columns.


The following SQL command will create a table called contacts as described above:
CREATE TABLE contacts ( contact_id INT(10),
name VARCHAR(40),
birthdate DATE
);

To add a column called email to the contacts table created with a datatype of ARCHAR(80), use the following SQL statement:
ALTER TABLE contacts ADD email VARCHAR(60);
This first statement will add the email column to the end of the table. To insert the new column after a specific column, such as name, use this statement:
ALTER TABLE contacts ADD email VARCHAR(60) AFTER name;
If you want the new column to be first, use this statement:
ALTER TABLE contacts ADD email VARCHAR(60) FIRST;

How to enable / change password of root user in Mountain Lion


Enable Root User in OS X Lion

This process also sets a password for the root account.
    • From the Mac OS X Desktop, hit Command+Shift+G to bring up Go To Folder and enter the following path:
/System/Library/CoreServices/
Directory Utility located within CoreServices
  • Inside CoreServices folder, locate and launch “Directory Utility”
  • Unlock “Directory Utility” by clicking the padlock icon and entering the administrator password
  • Pull down the “Edit” menu and select “Enable Root User”
  • Enter and confirm a password to set the root users password and to enable the account
Be sure to set a strong password for the root account. If you’re bad at picking passwords or you just want the security advantages of randomness, generate one randomly from the command line.
Enable Root User in Mac OS X Lion
With root now enabled, the account can be used freely. It will not appear in the Users & Groups preference pane.
The root account can access, read, and write to all files on a system, even if they belong to someone else. Additionally, root can also remove or replace system files. This is why it’s a potential security risk to leave the account enabled aimlessly, or to use a weak password with the account.
The Directory Utility control panel can also be used to change a set root password through the Edit menu, or that can be done through the command line using sudo passwd, similar to changing the root password in iOS devices.