版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、SQL 語(yǔ)句實(shí)現(xiàn)附加數(shù)據(jù)庫(kù)很簡(jiǎn)單-附加數(shù)據(jù)庫(kù)sp_attach_db '數(shù)據(jù)庫(kù)名 ','數(shù)據(jù)庫(kù)全路徑 ','數(shù)據(jù)庫(kù)日志全路徑 GO sp_attach_db 'Asset_National','.dataAsset_National.mdf','.dataAsset_National_log.LDF' GOUSE 數(shù)據(jù)庫(kù)名-添加一個(gè)登錄前指定默認(rèn)數(shù)據(jù)庫(kù)EXEC sp_addlogin '登錄名 ','密碼','數(shù)據(jù)庫(kù)名 'GO-處理空登錄名 (使登錄用戶和數(shù)據(jù)
2、庫(kù)的孤立用戶對(duì)應(yīng)起來(lái),在這個(gè)用戶有對(duì)象時(shí)用)sp_change_users_login 'update_one',登錄名','登錄名'GO-修改數(shù)據(jù)庫(kù)的邏輯文件名(數(shù)據(jù))ALTER DATABASE NEWMODIFY FILE(NAME='Old_Data',NEWNAME='New_Data')GO-修改數(shù)據(jù)庫(kù)的邏輯文件名(日志)ALTER DATABASE NEWMODIFY FILE(NAME='Old_Log',NEWNAME='New_Log')GO可能會(huì)用到的操作 :-更改當(dāng)前
3、數(shù)據(jù)庫(kù)名稱為 dbo 的登錄名為 abcEXEC sp_changedbowner 'abc'-刪除一個(gè)登錄EXEC sp_droplogin ' 登錄名 '-賦予這個(gè)登錄訪問(wèn)數(shù)據(jù)庫(kù)的權(quán)限EXEC sp_adduser '登錄名 ','用戶名 ','db_owner' 手動(dòng)實(shí)現(xiàn)方法: 無(wú)錯(cuò)版 SQL Server 2000 using System;using System.Collections.Generic; using System.ComponentModel;using System.Data;usin
4、g System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace Systempublic partial class Form1 : Formpublic Form1()InitializeComponent();public string ConnectionString;private SqlConnection Conn;private SqlCommand Comm;public string StrSQL;public string DataBase
5、Name;public string DataBase_MDF;public string DataBase_LDF;public string DataBaseOfBackupName;public string DataBaseOfBackupPath;private void Form1_Load(object sender, EventArgs e) C;DataBaseName = "risheng"DataBase_MDF = "E:risheng_Data.MDF"DataBase_LDF = "E:risheng_Log.LDF
6、"AddDataBase();/ <summary>/ 執(zhí)行創(chuàng)建 /修改數(shù)據(jù)庫(kù)和表的操作/ </summary>public void DataBaseAndTableControl()tryConn = new SqlConnection(ConnectionString);Conn.Open();Comm = new SqlCommand();Comm.Connection = Conn;Comm.CommandText = StrSQL;Comm.CommandType = CommandType.Text;Comm.ExecuteNonQuery();
7、MessageBox.Show( " 數(shù) 據(jù) 庫(kù) 操 作 成 功 ! ", " 信 息 提 示 " MessageBoxButtons.OK, MessageBoxIcon.Information);catch (Exception ex)MessageBox.Show(ex.Message, " 信 息 提 示 ", MessageBoxButtons.OK, MessageBoxIcon.Information);finallyConn.Close();/ <summary>/ 附加數(shù)據(jù)庫(kù)/ </summary&
8、gt;public void AddDataBase() tryConn = new SqlConnection(ConnectionString);Conn.Open();Comm = new SqlCommand();Comm.Connection = Conn;Comm.CommandText = "sp_attach_db""dbname","filename1","filename2",息 提 示 ",Comm.Parameters.Add(new SqlParameter(SqlDbType.
9、NVarChar);Comm.Parameters "dbname".Value = DataBaseName;Comm.Parameters.Add(new SqlParameter(SqlDbType.NVarChar);Comm.Parameters "filename1".Value = DataBase_MDF;Comm.Parameters.Add(new SqlParameter(SqlDbType.NVarChar);Comm.Parameters "filename2".Value = DataBase_LDF;Co
10、mm.CommandType = CommandType.StoredProcedure;Comm.ExecuteNonQuery();MessageBox.Show( " 附 加 數(shù) 據(jù) 庫(kù) 成 功 ", " 信MessageBoxButtons.OK, MessageBoxIcon.Information);catch (Exception ex)MessageBox.Show(ex.Message, " 信 息 提 示 ", MessageBoxButtons.OK,MessageBoxIcon.Information);finallyC
11、onn.Close();/ <summary>/ 分離數(shù)據(jù)庫(kù)/ </summary>public void DeleteDataBase()tryConn = new SqlConnection(ConnectionString);Conn.Open();Comm = new SqlCommand();Comm.Connection = Conn;Comm.CommandText = "sp_detach_db"Comm.Parameters.Add(new SqlParameter( "dbname",SqlDbType.NVa
12、rChar);Comm.Parameters "dbname".Value = DataBaseName;Comm.CommandType = CommandType.StoredProcedure;Comm.ExecuteNonQuery();MessageBox.Show( " 分 離 數(shù) 據(jù) 庫(kù) 成 功 ", " 信 息 提 示 ",MessageBoxButtons.OK, MessageBoxIcon.Information);catch (Exception ex)MessageBox.Show(ex.Message, &
13、quot; 信 息 提 示 ", MessageBoxButtons.OK,MessageBoxIcon.Information);finallyConn.Close();/ <summary>/ 備份數(shù)據(jù)庫(kù)/ </summary>public void BackupDataBase()tryConn = new SqlConnection(ConnectionString);Conn.Open();Comm = new SqlCommand();Comm.Connection = Conn;Comm.CommandText = "use maste
14、r;backup database dbname to disk = backupname;"Comm.Parameters.Add(new SqlParameter( "dbname", SqlDbType.NVarChar);Comm.Parameters "dbname".Value = DataBaseName;Comm.Parameters.Add(new SqlParameter( "backupname", SqlDbType.NVarChar);Comm.Parameters "backupname
15、".Value = DataBaseOfBackupPath + DataBaseOfBackupName;Comm.CommandType = CommandType.Text;Comm.ExecuteNonQuery();MessageBox.Show( " 備 份 數(shù) 據(jù) 庫(kù) 成 功 ", " 信 息 提 示 ", MessageBoxButtons.OK, MessageBoxIcon.Information);catch (Exception ex)MessageBox.Show(ex.Message, " 信 息 提 示
16、", MessageBoxButtons.OK, MessageBoxIcon.Information);finallyConn.Close();/ <summary>/ 還原數(shù)據(jù)庫(kù)/ </summary>public void ReplaceDataBase()trystring BackupFile = DataBaseOfBackupPath + DataBaseOfBackupName;Conn = new SqlConnection(ConnectionString);Conn.Open();Comm = new SqlCommand();Comm.
17、Connection = Conn;Comm.CommandText = "use master;restore database DataBaseName From disk = BackupFile with replace;"Comm.Parameters.Add(new SqlParameter( "DataBaseName", SqlDbType.NVarChar);Comm.Parameters "DataBaseName".Value = DataBaseName;Comm.Parameters.Add(new SqlP
18、arameter( "BackupFile", SqlDbType.NVarChar);Comm.Parameters "BackupFile".Value = BackupFile;Comm.CommandType = CommandType.Text;Comm.ExecuteNonQuery();MessageBox.Show( " 還 原 數(shù) 據(jù) 庫(kù) 成 功 ", " 信 息 提 示 "MessageBoxButtons.OK, MessageBoxIcon.Information);catch (Excep
19、tion ex)MessageBox.Show(ex.Message, " 信 息 提 示 ", MessageBoxButtons.OK, MessageBoxIcon.Information);finallyConn.Close();/ 還原數(shù)據(jù)庫(kù)private void button0_Click(object sender, EventArgs e)C;DataBaseName = "MyDatabase"DataBaseOfBackupName = "back.bak"FilesMicrosoft SQLFilesMicrosoftSQLFilesMicrosoftSQLDataBaseOfBackupPath = "D:ProgramServerMSSQLData"ReplaceDataBase();/ 附加數(shù)據(jù)庫(kù) private void button1_Click_1(object sender, EventArgs e) C;DataBaseName = "MyDatabase" DataBase_MDF="D:ProgramServerMSSQLDataMyDatabase_Data.MDF"DataBas
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024-2030年中國(guó)電鍍金剛石線行業(yè)市場(chǎng)發(fā)展趨勢(shì)與前景展望戰(zhàn)略研究報(bào)告
- 2024-2030年中國(guó)電網(wǎng)儲(chǔ)能產(chǎn)業(yè)產(chǎn)銷率分析與投資效益分析研究報(bào)告
- 2024-2030年中國(guó)電熱開(kāi)水器行業(yè)未來(lái)趨勢(shì)與前景需求潛力分析研究報(bào)告
- 2024-2030年中國(guó)電商行業(yè)市場(chǎng)發(fā)展分析及前景趨勢(shì)與投融資發(fā)展研究報(bào)告
- 2024-2030年中國(guó)電動(dòng)壁鋸行業(yè)市場(chǎng)發(fā)展趨勢(shì)與前景展望戰(zhàn)略研究報(bào)告
- 2024-2030年中國(guó)電力環(huán)保市場(chǎng)運(yùn)行動(dòng)態(tài)及重點(diǎn)企業(yè)發(fā)展規(guī)劃研究報(bào)告
- 2024-2030年中國(guó)甲鍺烷市場(chǎng)深度調(diào)查及未來(lái)發(fā)展趨勢(shì)研究研究報(bào)告
- 2024-2030年中國(guó)生物基聚對(duì)苯二甲酸乙二醇酯(Bio PET)行業(yè)市場(chǎng)發(fā)展趨勢(shì)與前景展望戰(zhàn)略研究報(bào)告
- 2024-2030年中國(guó)生態(tài)養(yǎng)豬行業(yè)市場(chǎng)發(fā)展分析及發(fā)展前景與投資風(fēng)險(xiǎn)研究報(bào)告
- 2024-2030年中國(guó)現(xiàn)代化養(yǎng)豬場(chǎng)行業(yè)發(fā)展分析及發(fā)展前景與趨勢(shì)預(yù)測(cè)研究報(bào)告
- 6S管理培訓(xùn)課件PPT(37張)
- 班會(huì)課 向陽(yáng)而生 追夢(mèng)而行
- 草原防火培訓(xùn)課件
- 糖尿病腎病血透護(hù)理查房課件
- 細(xì)菌性傳染病的護(hù)理管理
- 建筑施工現(xiàn)場(chǎng)的安全風(fēng)險(xiǎn)管理
- 煙道清理安全管理制度
- 《注射劑合理使用》課件
- 履行法定義務(wù)糾正違法行為的模板
- 化糞池清理安全操作及應(yīng)急預(yù)案范文
- 船舶入股協(xié)議
評(píng)論
0/150
提交評(píng)論