MSSQL Server Database Rename method

Source: Internet
Author: User
Tags mssql mssql server

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!") ")
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.