MySQL's alter command is very useful when you want to change the name of the table, the field of the table, or if you want to add or delete columns from an existing table.
Let's start by creating a use case with a table named Testalter_tbl:
The code is as follows
Copy Code
root@host# mysql-u root-p password;Enter password:*******mysql> use tutorials;Database changedMysql> CREATE TABLE Testalter_tbl-> (-> I INT,-> c CHAR (1
Detailed description of the use of the ALTER command in MySQL, mysqlalter
MySQL's ALTER command is very useful when you want to change the table name, table fields, or if you want to add or delete columns in an existing table.
Let's start to create a table named testalter_tbl:
root@host# mysql -u root -p password;Enter password:*******mysql> use TUTORIALS;Database changedmysql> create table testalter_tbl -
1. Specifying scope at set and reset is preceded by a specified SID parameter, otherwise an error occurs.
Sql> Show parameter open_cursors;
NAME TYPE VALUE------------------------------------ ----------- ------------------------------Open_cursors Integer 300
Sql> alter system set open_cursors=400 sid= ' * ' Scope=both;Alter system set open_cursors=400 sid= ' * ' Scope=both*ERROR at line 1:Ora-02065:illegal
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
Alter
Table
Name
Alter
Table
-Change table attributesSyntax
Alter
Table
Table
[
*
]
Add
[
Column
]
Column
Type
Alter
Table
Table
[
*
]
Common Lisp Object System (CLOS).
CREATE TABLE Films (Code CHARACTER (5) CONSTRAINT Firstkey PRIMARY KEY,Title CHARACTER varying (+) not NULL,Did DECIMAL (3) Not NULL,Date_prod DATE,Kind CHAR (10),Len INTERVAL HOUR to MINUTE);Please see the details: http://www.linuxforum.net/books/postgresNEW/sql-createtable.htm
ALTER TABLE--modifying the definition of tables
Add a varchar column to the table:
ALTER TABLE
Mysql exercise Alter usage summary bitsCN.com
Mysql exercise Alter usage summary
Alert usage summary:
Alter database syntax
Alter database is used to change the global features of a DATABASE. These features are stored in the db. opt file in the Database Directory. To use alter
MySQL is a relational database (RelationalDatabaseManagementSystem ). This article focuses on the alert commands of the mysql Database. This article is very detailed and has reference value. if you are interested, join us and learn that MySQL is a Relational Database Management System ), this so-called "relational" can be understood as "table". a relational database consists of one or more tables.
When we need to modify the data table name or field, we need to use the MySQL
I am used to the alter statements of oracle and cannot use these statements in db2. Example Table: createtableemp (idint, namechar (20), salaryd
I am used to the alter statements of oracle and cannot use these statements in db2. Example table: create table emp (id int, name char (20), salary d
I am used to the alter statements of Oracle and cannot use these
Renaming tablesThe basic syntax for renaming a table is:
The code is as follows
Copy Code
ALTER TABLE table_nameRENAME to New_table_name;For example:ALTER TABLE Suppliers
This will rename the Vendor table vendor.
Add column in table (S)Grammar #
To add to an existing table column, the syntax of ALTER table is:
The code is as follows
Copy Code
MySQL's alter command is very useful when you want to change the name of the table, the field of the table, or if you want to add or delete columns from an existing table.
Let's start by creating a use case with a table named Testalter_tbl:
root@host# mysql-u root-p password;
Enter password:*******
mysql> use tutorials;
Database changed
mysql> create TABLE Testalter_tbl
-> (
-> i INT,
-> C CHAR (1)
->); C9/>query OK, 0 rows affected (
5.6, we found that the alter column step is the same as the modify column step.
Mysql>Create Table Xs (name varchar (12), age int default 5 );Query OK, 0 rows affected (0.34 Sec)
Mysql>Insert into Xs values ('A', 4 );Query OK, 1 row affected (0.05 Sec)
Mysql>Set profiling = 1;Query OK, 0 rows affected, 1 warning (0.01 Sec)
Mysql>Alter table Xs modify age int not null default 3;
Query OK, 0 rows affected (0.
I am used to the alter statements of Oracle and cannot use these statements in db2.
The example table is as follows:
Create table emp (id int, name char (20), salary decimal (); -- create table emp
The alter statement usage of db2 is as follows:
(1) Add Columns
Alter table emp add sex char (1); --- add sex column
(2) Change the field type
First, basic usage
1. Add Column
ALTER TABLE Tbl_name add col_name type
For example, add a column of weight to the pet table,
Mysql>alter table Pet Add weight int;
2. Delete Column
ALTER TABLE Tbl_name drop col_name
For example, delete the weight column in the pet table
Mysql>
Label:DB2-alter Append/delete/reset column operation 1. Add field ALTER TABLE name add field name type DEMO:1 ALTER TABLE table_name NBSP;ADD N Bsp;column_test VARCHAR (50); 2. Change the field type ALTER TABLE name ALTER COLUMN field name set data type type DEMO: 1
Label:MySQL how to properly change a large table structure (Alter table structure of a single columnHttp://blog.sina.com.cn/s/blog_445e807b0101egpf.htmlFound on the Internet a very helpful three-paragraph script, posted for reference, readers, make a note:## Script 1# Alter table Structure of a single column of a large table#CREATE TABLE workingtablenew like workingtable;
Tags: mysql alter commandLin Bingwen Evankaka Original works. Reprint please specify the source Http://blog.csdn.net/evankakaThis article explains in detail the use of the ALTER command in MySQL syntax, which is a much more useful syntax, and the functionality is very powerful.Use the learning;
Create TABLE student (ID INT not NULL,
name CHAR (TEN) not NULL, class INT is not NULL,
A GE INT
);take a look at
ADD a field in the classic usage of the alter statement in mysql: alter table table_name ADD field_name field_type; www.2cto.com modify the original field name and type: alter table table_name CHANGE old_field_name new_field_name field_type; Delete the field: alter table table_name DROP field_name example change to aut
When creating a table, we will inevitably consider the disadvantages of weeks. Therefore, we need to use the alter table statement to modify the table later.Modify Table Name Copy codeThe Code is as follows:Mysql> alter table student rename person;Query OK, 0 rows affected (0.03 sec) Student is the original name and person is the modified name.Rename or renameModify the Data Type of a field Copy codeThe Cod
When we create a table, we will inevitably think of it poorly, so we later modify the table modification table to use the ALTER TABLE statement
Modify Table name
Copy Code code as follows:
mysql> ALTER TABLE student rename person;
Query OK, 0 rows affected (0.03 sec)
The student here is the original name, the person is after the modified names
Rename with rename, or you can use r
Tags: reference HTML div mys full serve data type EOF modifiedSqlALTER TABLE Statement
ALTER TABLE StatementThe ALTER table statement is used to add, delete, or modify columns in an existing table.SQL ALTER TABLE SyntaxTo add columns to a table, use the following syntax: ALTER TABLE table_name
ADD column_name d
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.