Home  >  Article  >  Database  >  mssql server数据库重命名方法

mssql server数据库重命名方法

WBOY
WBOYOriginal
2016-06-07 17:47:081795browse

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

(      
  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

下面我们来看一下用重命名数据库吧。
重命名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("重名名表成功!")
%>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn