Modify the table name and field name in an SQL statement.
Today, we have a temporary task to modify the database table name and field name in the production environment. In the past, the field names of the table names to be modified were all in
In the reconstruction of the site, the data structure is usually modified, so add, delete, add the MySQL table field is unavoidable, and sometimes for convenience, but also increase the modification of the table or field comments, the same field
In the reconstruction of the site, the data structure is usually modified, so add, delete, add the MySQL table field is unavoidable, and sometimes for convenience, but also increase the modification of the table or field comments, the same field
In mysql, we only need to use alter to modify the data table fields. Below I will introduce how to modify the table field name, field length, and field type in mysql, for more information, see.
Let's take a look at common methods.
The simple Syntax
To modify the field type and field name in SQL Server
--Here is the complete SQL execution statement
if exists (SELECT * from syscolumns where id=object_id (' datasheet name ') and name= ' field name ')--determine if the field exists
Begin
Alter
In the reconstruction of the site, the data structure is usually modified, so add, delete, add the MySQL table field is unavoidable, and sometimes for convenience, but also increase the modification of the table or field comments, the same field
No more nonsense to say, the details are as follows:
1. Modify the table name
Format: sp_rename tablename,newtablename
2. Modify Field Name
Format: sp_rename ' Tablename.colname ', Newcolname, ' column '
3. Add fields
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.