1. Modify the table fields:
Modify the Data Type of a column (generally, the length is limited and there are many restrictions when you change it to a different type ):
Syntax: alter table name MODIFY (column name data type );
Eg1: alter table skate_test modify (author number (10, 0 ));
When modifying the column length, you can only change it to a longer length than the existing field actually saves; otherw
Encounter Ora-14047:alter table| INDEX RENAME May is combined with other operations error[[emailprotected] ~]$ sqlplus lc0029999/aaaaaasql*plus:release 11.2.0.4.0 Production on Wed June 00:11:32 2015Copyright (c) 1982,-Oracle. All rights reserved. Connected to:oracle Database 11g Enterprise Edition Release 11.2.0.4.0-64bit productionwith The partitioning, OLAP, Data Mining and Real application testing optionssql>
Sql–altertable of Contents
Character
Engine
Add Drop
Primary key:
FOREIGN key
Default
Modify Change
Rename generally cannot be changed, the data may be wrong to change
CharacterCreate database test; Alter character set UTF8; Alter character set GBK;Create table user1; Alter Table User1 character set GBK;
When creating a table, we will inevitably consider the disadvantages of weeks. Therefore, we need to use altertable to modify the TABLE statement to modify the table later. Next we will introduce it in detail. For more information, see
When creating a table, we will inevitably consider the disadvantages of weeks. Therefore, we need to use alter table to modify the table statement to modify the table later. Next we will introduce it in detail. For more
// Primary key
AlterTable tabelname add new_field_id int (5) unsigned default 0 not null auto_increment, add primary key (new_field_id );
// Add a new column
Alter table T2 add D timestamp;Alter table Infos add ex tinyint not null default '0 ';
// Delete a column
Alter table T2 drop column C;
// Rename a column
The MySQL ALTER TABLE command is used to modify the table structure, such as adding/modifying/deleting fields, indexes, primary keys, and so on, and this article introduces the use of the MySQL ALTER TABLE statement through an example,
The MySQL alter syntax is as follows:
ALTER [IGNORE] TABLE tbl_name alter_s
Change database name
(1)
ALTER DATABASE database_name
Modify Name=new_database_name
(2)
Sp_renamedb Olddbname,newdbname
Add data files and filegroups (expand)
(1) Add data file
Use master
Go
DECLARE @data_path nvarchar (256);
--Get the location of the master data file
SELECT @data_path =physical_name
From MyDatabase.sys.database_files
WHERE file_id=1;
SET @data_path =substring (@data_path, 1, CHARINDEX (LOWER (' Mydatabase.mdf '), LOWER
PostgreSQL version: Psql (9.3.4)
1. Add a column
Copy Code code as follows:
ALTER TABLE table_name ADD column_name datatype;
2, delete a column
Copy Code code as follows:
ALTER TABLE table_name DROP column_name;
3, change the data type of the column
Copy Code code as follows:
ALTER TABLE TABLE_NA
PostgreSQL version number: Psql (9.3.4)1. Add a row of ALTER TABLE table_name ADD COLUMN_NAME datatype; 2. Delete a list of ALTER TABLE table_name drop column_name; 3. Change the data type of the column ALTER TABLE table_name ALTER column_name type datatype;
MySQL study Note 5: modifying the table (altertable) bitsCN.com we will inevitably consider the week before creating the table. Therefore, the alter table statement is required to modify the table later.
Modify table name
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 rename
Modify the data type of
Alter table table_name enable row movement, altertable_name
Row movement is literally interpreted as moving rows. by default, a row in an oracle data block does not move in its lifecycle, that is, its rowid does not change. however, in some scenarios, we want the row rowid to change. In this case, we need to start the row movement feature of the table.
Use the following statement to enable the row movement feature:
Label:The alter ADD command is used to increase the table's fields.Alter ADD command format: ALTER TABLE name add field type other;For example, a field passtest is added to table MyClass, the type is int (4), and the default value is 0:Mysql> ALTER TABLE MyClass add passtest int (4) default ' 0 ';1) Gazzo PrimerMysql> ALTER
Alter index index_name disable,enable for the function index.Sql> CREATE TABLE Test as SELECT * from All_objects;Sql> CREATE index ind_t_object_id on test (object_id) nologging;sql> exec dbms_stats.gather_table_stats (user, ' test ', cascade = TRUE);Sql> Set Autotrace traceonlySql> SELECT * FROM Test where object_id = 20;Execution plan----------------------------------------------------------Plan Hash value:255872589-----------------------------------
Tags: PostgreSQL alterPostgreSQL version: Psql (9.3.4)1, add a row of ALTER TABLE table_name ADD COLUMN_NAME datatype; 2. Delete a list of ALTER TABLE table_name drop column_name; 3. Change the data type of the column ALTER TABLE table_name ALTER column_name type datatyp
MySQL alter command, mysqlalter
Use the alter command in mysql to edit the table structure. The details are as follows:
Modify Field Type
mysql> alter table employee change depno depno int(5) not null;
Add Index
Mysql> alter table name add index name (field name 1 [, field name 2…]);
Example:
mysql>
Primary key
ALTER TABLE tablename Add new_field_id Int (5) UNSIGNED DEFAULT 0 not NULL anto_increment,add PRIMARY KEY (new_field_id);
Add a new column
Mysql>alter TABLE tablename ADD fieldname FieldType
Such as:
ALTER TABLE T2 ADD D TIMESTAMP;
ALTER TABLE infos ADD ex TINYINT not NULL DEFAULT ' 0 ';
Delete Column
Mys
Mysql alter table command to modify the table structure instance details, altertable
The mysql alter table statement can modify the basic structure of a table, such as adding a field, deleting a field, adding a primary key, adding an index, modifying the field data type, and renaming a table, this article introduces how to use mysql alter table through two simple
key,Username VARCHAR2 (+) NOT NULL,Age int Check (AGEGT;18 and age)CREATE TABLE Orders (OID VARCHAR2 (TEN) is not NULL,UserID Number (9),Primary KEY (OID),FOREIGN KEY (userid) references users (ID))Delete tables: drop table OrdersChange table name: ALTER TABLE ordersRename to OrderssJoin column: ALTER TABLE ordersAdd price number (9)Change the data type of the column:
Tags: mysql create alter dropDDL: Data Definition languageCREATEAlterDROPThe main operations focus on databases and tables.Database:To create a database:CREATE datebase| SCHEMA [IF not EXISTS] dbnane [create_specification];Create_sepecification[DEFAULT] CHARACTER Set [=] Charset_name Specify the default character setCOLLATE [=] Clooation_name] Specify collationTo modify a database:ALTER database| SCHEMA DBNAME alter_specification;Alter_psecification:C
We know that,MySQLDatabases are often combined with PHP to develop powerful applications. So for those who are new to PHP programming, it is necessary to understand some simple MySQL database operations. In this article, we useAlter tableStatement to modify the table structure. Next let's take a look at this part.
1. Add Columns
Alter table tbl_name add col_name type
For example, add a weight column to the pet table,
Mysql>
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.