1>ALTER TABLE --- ADD FieldName TINYINT AFTER ----
解决方案 »
- 插入固定表后排序变化问题:最后一位跑到第一位去了
- 每个分类取5条, 这样的SQL如何写??
- 一个sql的问题
- 求一个触发器
- 求 sql server 关于7306错误的解决方法...
- 为什么[name]字段名要加[]号?还有getdate()是什么函数?
- SQL 2005如何实现选择性表迁移!
- 请问怎样在SQL SERVER里面改数据库名,不重建数据库
- SQLServer2000个人版数据库删除了一个表的几条数据,能恢复吗??
- 紧急:SQL 2005启动后又停止求教
- 由于重装了系统,以前的SQL server 不能用了,我又重装了一次SQL server(不同目录下),原来那个里面的数据库怎样才能导到新的SQL SERV
- 关于日期格式问题
試了行的話﹐給我一個 sample如何 ﹐謝謝。
我用了如下SQL STATEMENT:ALTER TABLE Peronnel ADD FName varchar(100) AFTER FID
先说第一个问题,MSSQLSERVER2000:
假设在数据库'TEST'中有表'TAB',此表结构如下:
ID(int) NAME(varchar(8)) SEX(int)
--------------------------------------------
现在要把字段‘SEX’调到‘ID’的位置,既由3===>1,则程序如下:use master
go
sp_configure 'allow updates',1
reconfigure with override
go
use test --‘TEST’为你的数据库
go
declare @ltab varchar(50),@lcol varchar(50),@lorder int,@sum int,@cur int,@tempcur int
select @ltab='tab',@lcol='sex',@lorder=1 --定义要调的表、列和此列调动后的位置
if not exists(select * from sysobjects where id=object_id(@ltab))
begin
print 'The table '+@ltab+' is not exists!'
end
select @sum=count(*) from syscolumns where id=object_id(@ltab)
if @sum=0
begin
print 'The column '+@lcol+' is not exists!'
end
if @lorder>@sum or @lorder<1
begin
print 'The order '+cast(@lorder as varchar(100))+' out limit:[1,'+cast(@sum as varchar(100))+']!'
end
select @cur=colid from syscolumns where id=object_id(@ltab) and name=@lcol
select @tempcur=@sum+1
update syscolumns set colid=@tempcur where id=object_id(@ltab) and name=@lcol
if @lorder>@cur --向后调
update syscolumns set colid=colid-1 where id=object_id(@ltab) and colid>@cur and colid<=@lorder
if @lorder<@cur --向前调
update syscolumns set colid=colid+1 where id=object_id(@ltab) and colid>=@lorder and colid<@cur
update syscolumns set colid=@lorder where id=object_id(@ltab) and name=@lcol
print 'The column '+@lcol+' is on the order!'
go
use master
go
sp_configure 'allow updates',0
reconfigure with override
go声明:由于此过程要对系统表进行操作,一定要慎重!出现问题,概不负责!
有沒有更簡單的??
做一個動態字段的系統﹐比如薪資系統其薪資項目動態增減﹐采用3層結構似乎實現起來很難(用.net實現)﹐因為更新的時候﹐ADO.NET必須有實際欄位名稱及對應的參數(比如updateSqlCommand)傳入,而由于欄位是動態的﹐所以無法在中間層明確定義商業邏輯。因而建立sqlCommand對象時必須動態的生成。在傳統ado中﹐可以直接綁定recordset到一個控件﹐比如DataGrid﹐而不管字段名稱及個數等信息﹐進行更新;然而﹐ado.net似乎沒有提供這樣的功能﹐因為SqlCommand對象必須提供明確的參數才能執行﹐由于字段是動態的﹐所以參數的個數及類型名稱都無法明確確定。由于沒有更深入了解ado.net,所以請教解決方法.
一样进行错误处理,而不是在每个可能出现错误的语句后面用 @@ERROR 判断.没别的方法,我曾找过微软.