original varchar (25) to varchar (20)
Modify Field name
The Code is as follows:
Mysql> alter table person change stu_name name varchar (25 );
Query OK, 0 rows affected (0.20 sec)
Records: 0 Duplicates: 0 Warnings: 0
Stu_name is the original name and name is the new name.
It should be noted that no matter whether the data type is changed, the subsequent data
The ALTER TABLE statement is used to add, modify, or delete a column's original table in an existing table:first, Alter adds a new column to the table
syntax:ALTER
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数据库
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 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 table ta
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
Label:Get ready:CREATE table t (x int,y int); Usage 1:Modifying a column's data classALTER TABLE t modify column y nvarchar (32); Usage 2:Add a column to a tableALTER TABLE t add
type.Tips: we can also use change to achieve the modify effect. We only need to write the same field name after it.Add fields without integrity constraints Copy codeThe Code is as follows:Mysql> alter table person add sex boolean;Query OK, 0 rows affected (0.21 sec)Records: 0 Duplicates: 0 Warnings: 0 The sex here is followed by only the data type, without the i
ALTER TABLE changes the table to the current character set. If a duplicate key error is encountered during the execution of the ALTER TABLE operation, the new character set maps 2 keys to the same value or the table is corrupted.
The following articles mainly describe the information related to MySQL Alter Table function leakage. If you are using MySQL Alter Table, you can use the following articles to study it!
Affected Systems:
MySQLABMySQL5.1.x
The MySQL Replication encountered the following error message: (mysql> show slave status\g # simplified message below)
last_errno:1580Last_error:error ' You cannot ' ALTER ' a log table if logging are enabled ' on query. Default database: ' MySQL '. Query: ' ALTERTABLE Slow
A collection of SQL statements for the ALTER TABLE of MySQL, including adding, modifying, deleting fields, renaming tables, adding, deleting primary keys, and so on.
1: Delete Column
ALTER table "
SQL Server has a strange problem (2000/2005 all have this problem ):
The mm_bjjhmx table has the ID of the auto-increment column of the primary key, and a column "sequence number" is also required ".
Run the following statements:
Select Identity (INT, 1, 1) XH, A. * into # TBFrom mm_bjjhmxWhere bjjhid = 4Order by A. bjbm, A. bjmc;Select * from # TBDrop
The following error is reported when I try to modify the primary key of the MySQL data table with Navicat to automatically grow1602 ALTER TABLE causes auto_increment resequencing, resulting in duplicate entry ' 1′for key ' PRIMARY 'Workaround:1th Step: Change the value of the primary key field to 0 for any number that
Note: SQL Server 2005 and later versions are supported. This version is estimated to be not supported (working environment ).
To work, you need to add a new column to the existing SQL Server table and add a description. The stored procedure is as follows (attach the stored procedure first and then explain)
Code
1, the first Data training Xltrabackup backup, be prepared, remember to remember!2.Mysql-uroot-pd********--export CSV file use dsideal_db; MariaDB [dsideal_db]> SELECT * fromT_resource_info into OUTFILE"/usr/local/mysql/t_resource_info.txt"Fields TERMINATED by','Optionally enclosed by'"'LINES TERMINATED by'\ n'; Query OK,1582463Rows Affected (29.97sec) 3, slicing CSV file, so batch import faster, more conve
Note: SQL Server 2005 and above support. Version estimates are not supported (working environment 2005,2008).
To work, you need to add a new column to the existing table in SQL Server and add a description. Thus there is a stored procedure as follows. (Attach the stored procedure and then explain)
/******** Invok
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.