How can you rename a column in SQL?

In SQL, you can use the `ALTER TABLE` statement to rename a field. The specific syntax will depend on the database system being used. Here is a general example:

ALTER TABLE 表名

RENAME COLUMN 原字段名 TO 新字段名;

For example, let’s say we have a table called `employees` with a field `emp_name` that we want to rename to `name`, we can do the following:

ALTER TABLE employees

RENAME COLUMN emp_name TO name;

Please note that different database systems may have slight differences, so when using them, refer to the respective documents and syntax rules based on the system being used.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds