How to rename the mssqlserver Database

Source: Internet
Author: User
Tags mssql server mssqlserver
Mssqlserver rename method createprockillspid (@ dbnamevarchar (20) & nbsp; as & nbsp; & nbsp; begin & nbsp; & nb mssql server rename Method
Create proc killspid (@ dbname varchar (20 ))
As
Begin
Declare @ SQL nvarchar (500), @ temp varchar (1000)
Declare @ spid int
Set @ SQL = 'Clare getspid cursor
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

Next let's take a look at renaming a database.
When you Rename an ACCESS or SQL Server database table name, you can open the database and rename the table. Use now

The following code allows you to rename a table on the Web page through Access and SQL Server databases. 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 be renamed: OldTableName
OTbl. Name = "NewTableName" 'New table Name
Set oCat = Nothing
Set oTbl = Nothing
Response. Write ("name duplicate! ")
%>
My databases and files are placed in the same folder.
The database uses a virtual path. The above code is implemented: In the "test. mdb" database, change the name of the "test" table

"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.exe cute (SQL)

Conn. close
Set conn = nothing
Response. Write ("name duplicate! ")
%>

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.