, modify table Employee ID field as the primary key primary keys
ALTER TABLE employee ADD PRIMARY KEY (ID)
4, modify table Employee ID field is unique index unique
ALTER TABLE employee ADD UNIQUE (ID)
5. Rename the ID field in
7.2.3 to create an index with an alter TABLE statementon tables that already exist, you can create indexes directly on one or several of the fields on the table by using the ALTER TABLE statement. The basic form is as follows:ALTER tabl
Alter is a very powerful feature. We can use ALTER to modify the data table name and some other operations, and let's look at an example of adding, deleting, and modifying the table name in the ALTER datasheet in MySQL.
Modify the data content in the MySQL database to del
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 numbe
error is prompted:
ORA-01439: to change the data type, the column to be modified must be empty
2. Add a column:
Syntax: alter table name ADD (column name data type );
Eg1: alter table skate_test ADD (author NUMBER (38,0) not null );
3. Change the column Name:
Syntax:
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:
SQL ALTER TABLE statements are important in PHP operations and will be explained in this article.
SQL ALTER TABLE Syntax
To add columns to a table, use the following syntax:
ALTER TABLE
The MySQL ALTER TABLE statement can modify the basic structure of the table, such as adding fields, deleting fields, adding primary keys, adding indexes, modifying field data types, renaming tables, and so on, and this article introduces the use of MySQL ALTER TABLE with two
, therefore, the entire modification operation is maintained for a long time.
Let's perform a test:
-- ====================================-- Use the test database db2use db2go -- ========== =======-- create test table create table test001 (C1 int identity ), c2 bigint) Go -- =======================-- import 2000 + rows of data into the test table insert into tes
Alter table only allows adding columns that can contain null values or specified the default definition.
If:
If exists (select 1 from sysobjects where name = n' tab _ test') and not exists (select 1 from sysobjects A, syscolumns B where B. id =. ID and B. name = n' Col _ test' and. name = n' tab _ test ')Alter
SQL ALTER TABLE syntax and example tutorial
After the alter table statement allows you to change the structure of a TABLE, it is created. Address terms that can be added to a new column. Existing columns may be deleted from the Drop clause
test where ID mysql> TRUNCATE TABLE test; #删除allMysql> select * from test;Empty Set (0.00 sec)
On top, modify the table name in the database, add and remove fields from the table.
mysql> Use GBK #进入gbk数据库mysql> desc test;+-------+----------+------+-----+---------+----------------+| Field | Type | Null | Key | Defaul
SQL ALTER TABLE Syntax and instance tutorial
The ALTER TABLE statement allows you to change the structure of a table after it has been created. New column can be added to the address clause. Existing columns may be deleted from the list of drop clauses used.
The syntax for
DB2 alter: Add/delete/Reset Column
1. Add Fields
Alter table [table_name] add [column_name] [column_type]
2. Change the field type
Alter table [table_name] alter column [column_name] Set Data Type [column_type]
Note: There ar
, because they cannot be used for null queries, therefore, to avoid null in fields frequently to be queried, you can use default to process them. However, if "unknown" cannot be replaced by any default value, it can only be identified by null. For example, the value of a field may be negative infinity to positive infinity. So what default will you use to identify
. The new field is always added to the end of the existing field list. Column-def can be any form that is allowed in create table and is subject to the following restrictions:
A field cannot have a primary key or a unique constraint.
Fields cannot have these default values: Current_time, current_date, or Current_timestamp
If a NOT NULL constraint is defined, the field must have a non-empty
Oracle Constraints
* If a constraint only applies to individual fields, you can define the constraint at the field level or at the table level. However, if a constraint acts on multiple fields,Constraints must be defined at the table level* When defining a constraint, you can use the constraint keyword to name the constraint. If not specified, oracle automatically creates a default name for the constraint.
The following error was reported when modifying the auto-grow value of the table's primary key:mysql> ALTER TABLE YOON change COLUMN ID ID INT (one) not NULL auto_increment ADD PRIMARY KEY (ID);Error 1064 (42000): You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use-near ' ADD-PRIMARY KEY (ID) ' a
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.