当前位置:数据库 > SQLServer >>

mssql server数据库重命名方法

mssql server数据库重命名方法
create proc killspid (@dbname varchar(20))      
  as      
  begin      
  declare     @sql     nvarchar(500),@temp   varchar(1000)  
  declare     @spid     int      
  set     @sql='declare     getspid     cursor     for          
  select     spid     from     sysprocesses     where     dbid=db_id

('''+@dbname+''')'      
  exec     (@sql)      
  open     getspid      
  fetch     next     from     getspid     into     @spid      
  while     @@fetch_status   =0  
  begin      
      set   @temp='kill'+rtrim(@spid)  
      exec(@temp)  
  fetch next from getspid into @spid      
  end      
  close     getspid      
  deallocate &nb

下面我们来看一下用asp重命名数据库吧。
重命名ACCESS、SQL Server数据库中表名时,都是打开数据库然后重命名表。现在利用

下面代码可以实现在网页上也实现 Access、SQL Server数据库中重命名表。代码:
1、ACCESS
<%
Dim Conn,ConnStr,oCat,oTbl
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath

("test.mdb")
Set oCat=Server.CreateObject("ADOX.Catalog")
oCat.ActiveConnection = ConnStr
Set oTbl = Server.CreateObject("ADOX.Table")
Set oTbl = oCat.Tables("test") '要重命名的表名:OldTableName
oTbl.Name = "NewTableName" '新表名
Set oCat = Nothing
Set oTbl = Nothing
response.Write("重名名表成功!")
%>
我的数据库和文件是放在同个文件夹中。
数据库使用虚拟路径,上面代码是实现:在"test.mdb"数据库中将"test"表的名字改为

”NewTableName"。

2、SQL Server
代码如下:
<%
dim conn
set conn=CreateObject("ADODB.Connection")
conn.Open

("Provider=SQLOLEDB;Server=127.0.0.1;Database=test;UID=sa;PWD=QQ40623660")
sql = "sp_rename 'OldTableName', 'NewTableName', 'OBJECT'"
conn.execute(sql)

conn.close
set conn = nothing
response.Write("重名名表成功!")
%>

补充:数据库,Mssql 
Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,