MSSQL Server Database Rename method
Create proc killspid (@dbname varchar)
as
begin
DECLARE @sql nvarchar (+), @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
Let's take a look at using ASP to rename the database.
When you rename an access, a table name in a SQL Server database, you open the database and then rename the table. Now use
The following code implements the Rename table in Access and SQL Server databases on Web pages as well. Code:
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") ' Name of the table to rename: Oldtablename
Otbl.name = "Newtablename" ' New table name
Set OCat = Nothing
Set otbl = Nothing
Response. Write ("Duplicate Name table success!") ")
%>
My database and files are in the same folder.
The database uses a virtual path, and the code above is implementation: in the "Test.mdb" database, change the name of the "test" table to
"Newtablename".
2, SQL Server
The code is as follows:
<%
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 ("Duplicate Name table success!") ")
%>