在现有列之前添加列?

Aja*_*jay 5 mysql

我有 sql server 方面的知识,但现在由于我公司的要求,我在 MySQL 上工作。是否可以在指定列之前添加一列。

其实我试过这个逻辑

alter table marks add telugu int after typeofexam;
Run Code Online (Sandbox Code Playgroud)

它有效。当我尝试执行以下逻辑时

alter table marks add telugu int before typeofexam;
Run Code Online (Sandbox Code Playgroud)

其中marks是表名,telugu是列名,typeofexam是列名,它显示语法错误。

你能帮我弄明白逻辑吗?

exu*_*sum 9

使用FIRST关键字:

alter table marks add telugu int FIRST;
Run Code Online (Sandbox Code Playgroud)

文档:http : //dev.mysql.com/doc/refman/5.1/en/alter-table.html

无论如何,订单没什么大不了的。它更像是一个人的事情而不是一个要求。不过,大多数前端将允许您轻松重新订购。


Aur*_*urA 2

实际上,列的顺序在数据库中并不重要,您始终可以创建一个视图,该视图将按照您想要的列的顺序显示。

这是一个不错的博客,其中讨论了 SQL Server 的它们,但同样也适用于 MySQL。 http://blog.sqlauthority.com/2008/04/08/sql-server-change-order-of-column-in-database-tables/