Wednesday, May 27, 2015

Basic Sql Statements for MySQL

These are some basic Sql Statements I have used to work with MySQL database:

To insert new column in an existing table:

To add a column with data type equivalent to nvarchar in MSSQL
ALTER TABLE users ADD remarks varchar(1000) charset utf8;

To add a column after a specific column
ALTER TABLE users ADD status tinyint AFTER name;

To add a column at the first place
ALTER TABLE users ADD id int FIRST;

To delete a column from an existing table:

ALTER TABLE users DROP COLUMN status;

To rename a column from an existing table:

ALTER TABLE users CHANGE COLUMN oldName newName VARCHAR(255) NOT NULL;

To delete a record from an existing table:

DELETE FROM users WHERE Id=1;







No comments:

Post a Comment