SIGN UP MEMBER LOGIN:    
ARTICLE

Modifying and Updating Tables in MySQL

Posted by Arjun Panwar Articles | Databases & DBA December 12, 2011
This article explains how to modify and update a table in MySQL.
Reader Level:

Modifying :

Definition: The modify command is used when we have to resize a column in a table. By using this command we have to apply some changes on the result set field. This command allows more or less characters than before.

Syntax :
alter table modify [column name] VARCHAR(5) ;

Also Known As: It also known as the Modify Column, Resize Column into a table in a database.

Examples:  alter table people modify name VARCHAR(35);

img-1.gif

Add a new column to db.

alter table [table name] add column [new column name] varchar (20);

img-2.gif

Delete a column.

alter table [table name] drop column [column name];

img-3.gif

Change column name:

alter table [table name] change [old column name] [new column name] varchar (50);

img-4.gif

Make a unique column so you get no dupes.

alter table [table name] add unique ([column name]);

Make a column bigger.

alter table [table name] modify [column name] VARCHAR(4);

Delete unique from table.

alter table [table name] drop index [column name];

Updating :

It is necessary to change the data in our database, so these commands are helpful for update a table.

Example : UPDATE products SET product_id = 7, product_name='headphone', c_id=6,price=1201;

img-5.gif

To update info already in a table.
UPDATE [table name] SET Select_priv = 'Y',Insert_priv = 'Y',Update_priv = 'Y' where [field name] = 'user';

Delete a row(s) from a table.
DELETE from [table name] where [field name] = 'something';

Update database permissions/privilages.
FLUSH PRIVILEGES;

Load a CSV file into a table.
LOAD DATA INFILE '/tmp/filename.csv' replace INTO TABLE [table name] FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (field1,field2,field3);

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor