- 论坛徽章:
- 6
|
已经找到调整列的顺序的方法了。
下面是测试例子:
先建立一个新的测试表test
1> drop table test
2> go
1> create table test(id int not null,name varchar(30) null,age tinyint not null,
se_x char(1) not null,birthday datetime null)
2> go
1> select * from test
2> go
id name age se_x birthday
----------- ------------------------------ --- --- --------------------------
(0 rows affected)
插入一条测试数据
1> insert into test
2> values(1,'andkylee',28,'F','1982-03-20 12:00:00')
3> go
(1 row affected)
1> select * from test
2> go
id name age se_x birthday
----------- ------------------------------ --- --- --------------------------
1 andkylee 28 F Mar 20 1982 12:00PM
(1 row affected)
调整各个的顺序,使之倒序。将原来的id,name,age,se_x,birthday改成:birthday,se_x,age,name,id
调整方法:修改syscolumns表中测试表test的各个列的colid的顺序。
1> select * from test
2> go
birthday se_x age name id
-------------------------- --- --- ------------------------------ -----------
Mar 20 1982 12:00PM F 28 andkylee 1
(1 row affected)
列的顺序逆序后,显示插入数据。
1> insert into test(id,name,age,se_x,birthday)
2> values(2,'liu',30,'M','2000-01-01 11:59:59')
3> go
(1 row affected)
1> select * from test
2> go
birthday se_x age name id
-------------------------- --- --- ------------------------------ -----------
Mar 20 1982 12:00PM F 28 andkylee 1
Jan 1 2000 11:59AM M 30 liu 2
(2 rows affected)
如果按照调整数据之前的列的顺序插入数据,则会报错。
1> insert into test
2> values(3,'zhang',29,'F','1980-01-01 11:59:59')
3> go
Msg 206, Level 16, State 2:
Server 'SYB_NFJD_TEST', Line 1:
Operand type clash: INT is incompatible with DATETIME
Msg 257, Level 16, State 1:
Server 'SYB_NFJD_TEST', Line 1:
Implicit conversion from datatype 'VARCHAR' to 'INT' is not allowed. Use the
CONVERT function to run this query.
新的数据要按照修改后的列的顺序插入。
1> insert into test
2> values('1980-01-01 11:59:59','F',29,'zhang',3)
3> go
(1 row affected)
最后,查看测试表的数据。
1> select * from test
2> go
birthday se_x age name id
-------------------------- --- --- ------------------------------ -----------
Mar 20 1982 12:00PM F 28 andkylee 1
Jan 1 2000 11:59AM M 30 liu 2
Jan 1 1980 11:59AM F 29 zhang 3
(3 rows affected)
备注:绝大多数sybase客户端工具显示表的列时都是按照colid的顺序显示的。所以,此法顶能实现你的要求。
|
|