1、分離數(shù)據(jù)庫(kù)
exec sp_detach_db dataname
--eg: dataname:要分離的數(shù)據(jù)庫(kù)名
2、附加數(shù)據(jù)庫(kù)
1
exec sp_attach_single_file_db newdataname,mdfPath
/*eg:
newdataname:要附加上的新數(shù)據(jù)庫(kù)名稱(可以是原來(lái)的)
mdfPath='C:/Program Files/Microsoft SQL Server/MSSQL/Data/11_Data.MDF'
*/
2.
exec sp_attach_db newdataname,mdfPath,ldfPath
/*eg:
mdfPath='C:/Program Files/Microsoft SQL Server/MSSQL/Data/11_Data.MDF'
ldfPath='C:/Program Files/Microsoft SQL Server/MSSQL/Data/11_Log.LDF'
*/
備注:不能操作本數(shù)據(jù)庫(kù)
復(fù)制C#代碼保存代碼string DataName = "aaa";
string strMdf = "D://test1//test//Test_Data.MDF";
string strLdf = "D://test1//test//Test_Log.LDF";
string strsql = @"EXEC sp_attach_db
@dbname = '" + DataName + @"',
@filename1='" + strMdf + @"',
@filename2= '" + strLdf + "'";
SqlConnection myConn = new SqlConnection("Data Source=HUIQIN;Database=master;Persist Security Info=True;UserID=sa;Password=sa");
SqlCommand myCommand = new SqlCommand(strsql, myConn);
myConn.Open();
myCommand.ExecuteNonQuery();
myConn.Close();
來(lái)源:freeliver54的VeVb
新聞熱點(diǎn)
疑難解答
圖片精選