MySQL add columns, modify columns, delete columns

Source: Internet
Author: User
Tags table name mysql database

ALTER table: Add, modify, delete table columns, constraints, and other table definitions.

View column: Desc table name;

Modify table name: ALTER TABLE T_book Rename to BBB;

Add column: ALTER TABLE name add column name varchar (30);

Delete column: ALTER TABLE name drop column column name;

Modify Column name Mysql:alter table BBB change nnnnn hh int;

Modify Column name Sqlserver:exec sp_rename ' t_student.name ', ' nn ', ' column ';

Modify Column name oracle:lter table BBB Rename column nnnnn to HH int;

Modify Column properties: ALTER TABLE T_book modify name varchar (22);

Sp_rename:sqlserver built-in stored procedures, with the definition of modifying the table.

MySQL Modify, delete data records

MySQL database is believed that many people have contacted, in the MySQL database operation, someone would like to delete or modify the MySQL database in some data records.

MySQL database is believed that many people have contacted, in the MySQL database operation, someone would like to delete or modify the MySQL database in some data records. The DELETE and UPDATE statements enable us to do this.

Modify records with update

UPDATE Tbl_name Set the column to change

The record WHERE you want to update

The WHERE clause here is optional, so if you do not specify it, each record in the table is updated.

For example, in the pet table, we found that the sex of the pet Whistler was not specified, so we can modify this record as follows:

Mysql> Update pet Set sex= ' F ' where name= ' Whistler ';

Delete Records with delete

The DELETE statement has the following format:

Delete from Tbl_name WHERE to delete records

The WHERE clause specifies which records should be deleted. It is optional, but if not selected, all records will be deleted. This means that the simplest DELETE statement is also the most dangerous.

This query clears all the contents of the table. You must be careful!

To delete a specific record, you can select the record you want to delete by using the WHERE clause. This is similar to the WHERE clause in the SELECT statement.

Mysql> Delete from pet where name= "Whistler";

You can empty the entire table with the following statement:

Mysql>delete from Pet;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.