SQL Alter methods to modify field types and names

Source: Internet
Author: User

SQL Alter methods to modify field types and names

ALTER TABLE "table_name"
[Change Mode]

Add a field: Add "Field 1" "Field 1 Data category"

MySQL Tutorials > CREATE TABLE Employee (
   ->     id             int,
   ->     first_ name    VARCHAR,
   ->     last_name      VARCHAR,
   ->     start_date    Date,
   ->     end_date      date,
    ->     salary        FLOAT (8,2),
    ->     city          VARCHAR (Ten),
   ->     description   VARCHAR (a)
   ->);
Query OK, 0 rows affected (0.03 sec)

Mysql>
Mysql>
Mysql> ALTER TABLE Employee
-> Change first_name FirstName VARCHAR (20);
Query OK, 0 rows affected (0.05 sec)
records:0 duplicates:0 warnings:0

Mysql>
Mysql> DESCRIBE employee;
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| ID | Int (11) |     YES | |       NULL | |
| FirstName | varchar (20) |     YES | |       NULL | |
| last_name | varchar (15) |     YES | |       NULL | |
| start_date | Date |     YES | |       NULL | |
| end_date | Date |     YES | |       NULL | |
| Salary | Float (8,2) |     YES | |       NULL | |
| City | varchar (10) |     YES | |       NULL | |
| Description | varchar (15) |     YES | |       NULL | |
+-------------+-------------+------+-----+---------+-------+
8 rows in Set (0.01 sec)

Modify field varchar type

mysql> ALTER TABLE Employee
-> Change last_name last_name VARCHAR (50);
Query OK, 0 rows affected (0.05 sec)
records:0 duplicates:0 warnings:0

Add an index to a field

mysql> ALTER TABLE myTable
-> ADD UNIQUE (OrderID, modelid);
Query OK, 0 rows affected (0.06 sec)

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.