波多在线播放_激情深爱五月_久久欧美精品_成人超碰_国产久_www.pixiv.moe


曙海教育集團論壇開發(fā)語言培訓(xùn)專區(qū)SQL Server數(shù)據(jù)庫 → 動態(tài)創(chuàng)建SQL Server數(shù)據(jù)庫、表、存儲過程等架構(gòu)信息


  共有7756人關(guān)注過本帖樹形打印

主題:動態(tài)創(chuàng)建SQL Server數(shù)據(jù)庫、表、存儲過程等架構(gòu)信息

美女呀,離線,留言給我吧!
wangxinxin
  1樓 個性首頁 | 博客 | 信息 | 搜索 | 郵箱 | 主頁 | UC


加好友 發(fā)短信
等級:青蜂俠 帖子:1393 積分:14038 威望:0 精華:0 注冊:2010-11-12 11:08:23
動態(tài)創(chuàng)建SQL Server數(shù)據(jù)庫、表、存儲過程等架構(gòu)信息  發(fā)帖心情 Post By:2010-12-13 12:35:44

------2003-9-4 12:59:31  


-------------------------------------------------------www.csdn.net

關(guān)鍵字     Sql Server,數(shù)據(jù)庫,創(chuàng)建
  
作者: 孟憲會 出自: 【孟憲會之精彩世界】 發(fā)布日期: 2003-8-17 23:34:35

下面是利用SQL語句創(chuàng)建數(shù)據(jù)庫、表、存儲過程、視圖、索引、規(guī)則、修改表、查看數(shù)據(jù)等的方法。所要增加的控件如下:

http://www.csdn.net/Develop/Arti ... 003-8-181234011.gif

Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
  Inherits System.Windows.Forms.Form
  Private ConnectionString As String = "Data Source=.;Initial Catalog=;User Id=sa;Password=;"
  Private reader As SqlDataReader = Nothing
  Private conn As SqlConnection = Nothing
  Private cmd As SqlCommand = Nothing
  Private AlterTableBtn As System.Windows.Forms.Button
  Private sql As String = Nothing
  Private CreateOthersBtn As System.Windows.Forms.Button

#Region " Windows 窗體設(shè)計器生成的代碼 "
  '窗體重寫處置以清理組件列表。
  Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
      If Not (components Is Nothing) Then
        components.Dispose()
      End If
    End If
    MyBase.Dispose(disposing)
  End Sub
  Public Sub New()
    MyBase.New()
    InitializeComponent()
  End Sub
  Private components As System.ComponentModel.IContainer
  Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
  Friend WithEvents CreateDBBtn As System.Windows.Forms.Button
  Friend WithEvents CreateTableBtn As System.Windows.Forms.Button
  Friend WithEvents CreateSPBtn As System.Windows.Forms.Button
  Friend WithEvents CreateViewBtn As System.Windows.Forms.Button
  Friend WithEvents btnAlterTable As System.Windows.Forms.Button
  Friend WithEvents btnCreateOthers As System.Windows.Forms.Button
  Friend WithEvents btnDropTable As System.Windows.Forms.Button
  Friend WithEvents btnViewData As System.Windows.Forms.Button
  Friend WithEvents btnViewSP As System.Windows.Forms.Button
  Friend WithEvents btnViewView As System.Windows.Forms.Button
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.CreateDBBtn = New System.Windows.Forms.Button()
    Me.CreateTableBtn = New System.Windows.Forms.Button()
    Me.CreateSPBtn = New System.Windows.Forms.Button()
    Me.CreateViewBtn = New System.Windows.Forms.Button()
    Me.btnAlterTable = New System.Windows.Forms.Button()
    Me.btnCreateOthers = New System.Windows.Forms.Button()
    Me.btnDropTable = New System.Windows.Forms.Button()
    Me.btnViewData = New System.Windows.Forms.Button()
    Me.btnViewSP = New System.Windows.Forms.Button()
    Me.btnViewView = New System.Windows.Forms.Button()
    Me.DataGrid1 = New System.Windows.Forms.DataGrid()
    CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
    Me.SuspendLayout()
    '
    'CreateDBBtn
    '
    Me.CreateDBBtn.Location = New System.Drawing.Point(19, 9)
    Me.CreateDBBtn.Name = "CreateDBBtn"
    Me.CreateDBBtn.Size = New System.Drawing.Size(104, 23)
    Me.CreateDBBtn.TabIndex = 0
    Me.CreateDBBtn.Text = "創(chuàng)建數(shù)據(jù)庫"
    '
    'CreateTableBtn
    '
    Me.CreateTableBtn.Location = New System.Drawing.Point(139, 9)
    Me.CreateTableBtn.Name = "CreateTableBtn"
    Me.CreateTableBtn.TabIndex = 1
    Me.CreateTableBtn.Text = "創(chuàng)建表"
    '
    'CreateSPBtn
    '
    Me.CreateSPBtn.Location = New System.Drawing.Point(230, 9)
    Me.CreateSPBtn.Name = "CreateSPBtn"
    Me.CreateSPBtn.Size = New System.Drawing.Size(104, 23)
    Me.CreateSPBtn.TabIndex = 2
    Me.CreateSPBtn.Text = "創(chuàng)建存儲過程"
    '
    'CreateViewBtn
    '
    Me.CreateViewBtn.Location = New System.Drawing.Point(350, 9)
    Me.CreateViewBtn.Name = "CreateViewBtn"
    Me.CreateViewBtn.TabIndex = 3
    Me.CreateViewBtn.Text = "創(chuàng)建視圖"
    '
    'btnAlterTable
    '
    Me.btnAlterTable.Location = New System.Drawing.Point(441, 9)
    Me.btnAlterTable.Name = "btnAlterTable"
    Me.btnAlterTable.TabIndex = 4
    Me.btnAlterTable.Text = "修改表"
    '
    'btnCreateOthers
    '
    Me.btnCreateOthers.Location = New System.Drawing.Point(17, 43)
    Me.btnCreateOthers.Name = "btnCreateOthers"
    Me.btnCreateOthers.Size = New System.Drawing.Size(104, 23)
    Me.btnCreateOthers.TabIndex = 5
    Me.btnCreateOthers.Text = "創(chuàng)建規(guī)則和索引"
    '
    'btnDropTable
    '
    Me.btnDropTable.Location = New System.Drawing.Point(138, 43)
    Me.btnDropTable.Name = "btnDropTable"
    Me.btnDropTable.TabIndex = 6
    Me.btnDropTable.Text = "刪除表"
    '
    'btnViewData
    '
    Me.btnViewData.Location = New System.Drawing.Point(351, 43)
    Me.btnViewData.Name = "btnViewData"
    Me.btnViewData.TabIndex = 7
    Me.btnViewData.Text = "查看數(shù)據(jù)"
    '
    'btnViewSP
    '
    Me.btnViewSP.Location = New System.Drawing.Point(230, 43)
    Me.btnViewSP.Name = "btnViewSP"
    Me.btnViewSP.Size = New System.Drawing.Size(104, 23)
    Me.btnViewSP.TabIndex = 8
    Me.btnViewSP.Text = "查看存儲過程"
    '
    'btnViewView
    '
    Me.btnViewView.Location = New System.Drawing.Point(443, 43)
    Me.btnViewView.Name = "btnViewView"
    Me.btnViewView.TabIndex = 9
    Me.btnViewView.Text = "查看視圖"
    '
    'DataGrid1
    '
    Me.DataGrid1.DataMember = ""
    Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
    Me.DataGrid1.Location = New System.Drawing.Point(20, 76)
    Me.DataGrid1.Name = "DataGrid1"
    Me.DataGrid1.Size = New System.Drawing.Size(500, 183)
    Me.DataGrid1.TabIndex = 10
    '
    'Form1
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(538, 281)
    Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.DataGrid1, Me.btnViewView, _
              Me.btnViewSP, Me.btnViewData, Me.btnDropTable, Me.btnCreateOthers, Me.btnAlterTable, _
              Me.CreateViewBtn, Me.CreateSPBtn, Me.CreateTableBtn, Me.CreateDBBtn})
    Me.Name = "Form1"
    Me.Text = "動態(tài)創(chuàng)建SQL Server數(shù)據(jù)庫、表、存儲過程等架構(gòu)信息"
    CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
    Me.ResumeLayout(False)

  End Sub

#End Region

  ' 創(chuàng)建數(shù)據(jù)庫
  Private Sub CreateDBBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles CreateDBBtn.Click
    conn = New SqlConnection(ConnectionString)
    ' 打開連接
    If conn.State <> ConnectionState.Open Then
      conn.Open()
    End If
    'MyDataBase為數(shù)據(jù)庫名稱
    Dim sql As String = "CREATE DATABASE MyDataBase ON PRIMARY (Name=MyDataBase_data, filename = " + _
        "'D:\MyDataBase.mdf', size=3," + "maxsize=5, filegrowth=10%) log on" + "(name=MyDataBase_log, " + _
        "filename='D:\MyDataBase.ldf',size=3," + "maxsize=20,filegrowth=1)"
    cmd = New SqlCommand(sql, conn)
    Try
      cmd.ExecuteNonQuery()
    Catch ae As SqlException
      MessageBox.Show(ae.Message.ToString())
    End Try
  End Sub
  '創(chuàng)建表
  Private Sub CreateTableBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles CreateTableBtn.Click
    conn = New SqlConnection(ConnectionString)
    ' 打開連接
    If conn.State = ConnectionState.Open Then
      conn.Close()
    End If
    C
    conn.ConnectionString = ConnectionString
    conn.Open()
    sql = "CREATE TABLE myTable" + "(myId INTEGER CONSTRAINT PKeyMyId PRIMARY KEY," + _
      "myName CHAR(50) NOT Null, myAddress CHAR(255), myValues FLOAT)"
    cmd = New SqlCommand(sql, conn)
    Try
      cmd.ExecuteNonQuery()
      ' 添加紀錄
      sql = "INSERT INTO myTable(myId, myName, myAddress, myValues) " + _
        "VALUES (1001, _'【孟憲會之精彩世界】之一', 'http://xml.sz.luohuedu.net/', 100 ) "
      cmd = New SqlCommand(sql, conn)
      cmd.ExecuteNonQuery()
      sql = "INSERT INTO myTable(myId, myName, myAddress, myValues) " + _
        "VALUES (1002, '【孟憲會之精彩世界】之二', 'http://www.erp800.com/net_lover/', 99) "
      cmd = New SqlCommand(sql, conn)
      cmd.ExecuteNonQuery()
      sql = "INSERT INTO myTable(myId, myName, myAddress, myValues) " + _
        "VALUES (1003, '【孟憲會之精彩世界】之三', 'http://xml.sz.luohuedu.net/', 99) "
      cmd = New SqlCommand(sql, conn)
      cmd.ExecuteNonQuery()
      sql = "INSERT INTO myTable(myId, myName, myAddress, myValues) " + _
        "VALUES (1004, '【孟憲會之精彩世界】之四', 'http://www.erp800.com/net_lover/', 100) "
      cmd = New SqlCommand(sql, conn)
      cmd.ExecuteNonQuery()
    Catch ae As SqlException
      MessageBox.Show(ae.Message.ToString())
    End Try

  End Sub
  '創(chuàng)建存儲過程
  Private Sub CreateSPBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles CreateSPBtn.Click
    sql = "CREATE PROCEDURE myProc AS" + " SELECT myName, myAddress FROM myTable GO"
    ExecuteSQLStmt(sql)
  End Sub
  '創(chuàng)建視圖
  Private Sub CreateViewBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles CreateViewBtn.Click
    sql = "CREATE VIEW myView AS SELECT myName FROM myTable"
    ExecuteSQLStmt(sql)

  End Sub
  '修改表
  Private Sub btnAlterTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles btnAlterTable.Click
    sql = "ALTER TABLE MyTable ADD newCol datetime NOT NULL DEFAULT (getdate())"
    ExecuteSQLStmt(sql)
  End Sub
  '創(chuàng)建規(guī)則和索引
  Private Sub btnCreateOthers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles btnCreateOthers.Click
    sql = "CREATE UNIQUE INDEX " + "myIdx ON myTable(myName)"
    ExecuteSQLStmt(sql)

    sql = "CREATE RULE myRule " + "AS @myValues >= 90 AND @myValues < 9999"
    ExecuteSQLStmt(sql)
  End Sub

  '刪除表
  Private Sub btnDropTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles btnDropTable.Click
    Dim sql As String = "DROP TABLE MyTable"
    ExecuteSQLStmt(sql)
  End Sub
  '    C
    conn.ConnectionString = ConnectionString
    conn.Open()
    Dim da As New SqlDataAdapter("SELECT * FROM myView", conn)
    Dim

支持(0中立(0反對(0單帖管理 | 引用 | 回復(fù) 回到頂部

返回版面帖子列表

動態(tài)創(chuàng)建SQL Server數(shù)據(jù)庫、表、存儲過程等架構(gòu)信息








簽名
主站蜘蛛池模板: 午夜免费 | 99久久精品费精品国产一区二区 | 婷婷激情五月综合 | 久久永久免费中文字幕 | 婷婷国产成人精品视频 | 日本一区二区视频在线 | 人人搞人人干 | 日本不卡一区二区三区在线观看 | 午夜爽爽性刺激一区二区视频 | 亚洲精品无码国产爽快A片百度 | 精品毛片| 在线播放高清视频www | 91看片淫黄大片一级在线观看 | 亚洲国产欧美91 | 免费亚洲视频在线观看 | 日韩色中色 | 国产国语一级a毛片高清视频 | 九九视频九九热 | 激情网五月天 | 91网站入口 | 久久久日韩精品一区二区 | 天天噜噜揉揉狠狠夜夜 | 精品视频在线免费播放 | 午夜视频在线观看视频 | 亚洲精品在 | 国产一级免费在线视频 | 视频一区二区三区免费观看 | 午夜在线小视频 | 国产99999| 草草视频在线观看 | 一级欧美毛片成人 | 亚洲AV国产精品无码A片 | 亚洲电影一区二区 | 天天怕夜夜怕狠狠怕 | 国产美女啪啪 | 九九在线精品视频 | 亚洲日本中文字幕永久 | 国产精品午夜电影 | 国产又黄又猛又粗又爽的A片动漫 | 一级毛片一级毛片一级毛片一级毛片 | 舒淇三级浴室洗澡在线观看 |