1. 程式人生 > >sql建立一個表並新增刪除欄位

sql建立一個表並新增刪除欄位

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        SqlConnection myconnection;
        SqlCommand mycommand;
        SqlDataReader myreader;
        string str = Properties.Settings.Default.connection;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            myconnection = new SqlConnection(str);
            myconnection.Open();
            string biao = this.textBox1.Text.Trim();
            //建立帶有一個自增欄位的表
            mycommand = new SqlCommand("create table ["+biao+"]([123] int IDENTITY (1,1) PRIMARY KEY,[12] nvarchar(50))", myconnection);
           // mycommand.Parameters.AddWithValue("@gongsi",this.textBox1.Text.Trim());
            myreader = mycommand.ExecuteReader();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            myconnection = new SqlConnection(str);
            myconnection.Open();
            string ziduan = this.textBox2.Text.Trim();
            //往表裡新增新欄位
            mycommand = new SqlCommand("alter table [阿里巴巴網路技術有限公司] add [" + ziduan + "] nvarchar(50)",myconnection);
            myreader = mycommand.ExecuteReader();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            myconnection = new SqlConnection(str);
            myconnection.Open();
           //判斷一個欄位是否在一個表裡
            mycommand = new SqlCommand("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE (TABLE_NAME [email protected] and [email protected])",myconnection);
            mycommand.Parameters.AddWithValue("@biao", this.textBox2.Text);
            mycommand.Parameters.AddWithValue("@ziduan", this.textBox3.Text);
            myreader = mycommand.ExecuteReader();
            if (myreader.Read())
            {
                MessageBox.Show("1");
            }
            else
            {
                MessageBox.Show("2");
            }
        }
    }
}

相關推薦

sql建立一個新增刪除

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using S

mysql將一個的資料插入到另外一個,如果某個已經存在將不插入的sql

insert into registerInfo_extend (userId,name) select userId,'遊客' from registerInfo where not exists (

建立帶有lobor 新增lob

--在oracle中建立帶有lob欄位的表,對於lob欄位,最好指定專用的lob 表空間,因為對LOB欄位進行update和Delete操作時候,它的Undo資訊不是放在Undo 表空間中, 而是放在

Oracle 將一個中幾個更新到另一個

UPDATE  TEST_TABLE1 T1    SET  (T1.AA, T1.BB, T1.CC) =      

MySql資料庫在新增,設定主鍵,設定外來鍵,移動位置,以及修改資料庫後如何進行部署和維護的總結

1,為當前已有的表新增新的欄位 alter table student add studentName varchar(20) not null; 2,為當前已有的表中的欄位設定為主鍵自增 alter table student add constraint PK_studentId primaryKe

oracle中,把一個中指定的資料更新到另外一張裡面

一、建立表結構 create table test1( id varchar2(10) , val varchar2(20), name varchar2(20)); create table test2( id varchar2(10), val varchar2(20) ,

oracle 用一個的多個更新另一個對應的多個

update wx_weather a set (a.high_l,a.low_l)= (select high_l, low_l from wx_original_weather b where a

Django Sqlite 資料庫,在已有新增

Django 使用預設的 sqlite 資料庫,想在已經建立的表中新增一個新的欄位,操作很簡單。 1、直接在你要新增新欄位的app的 models.py 檔案中新增,如下: # -*- coding

用oracle查詢一個中的一個內容包含另一個中的某個的值

select *   from table1 where exists (select 1           from table2          where table1.columA like '%' || table2.columB || '%')

python連線SQLServer資料庫建立資料同時為每個加上對應的中文註釋資訊

      今天應產品那邊的需求更改,需要在原始的建立資料表的指令碼中加入註釋這一項,SQLServer資料庫其實我是很不熟的,這一段時間完全是因為專案的緣故才會比較多的接觸到這一塊內容,學習一下覺得挺好的。之前的建立表的指令碼寫的也是很low的,當然現在也是比較low的,但

Oracle中將一個中某一的資料更新到另一個中某一

首先想到的sql:update 表2 set 表2.c=(select val from 表2 where 表1.a=表2.a);但這樣會出現在表1中有的行,如果在表2中沒有對應的行,值被更新為null

查詢不同sqlserver資料庫兩張比對結構是否相同

package com.cn.sis;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;im

Hive分割槽新增,值為NULL 問題解決

1. 如果當前Hive表不帶有分割槽,那麼可以直接使用alter table 表名 add columns(欄位名 string) 2.如果當前HIve錶帶有分割槽的,那麼可以使用 alter table 表名 partition(分割槽名='分割槽對應的值') add

oracle 一個新增多個,根據條件重新整理

2. Oracleupdate TA a set(name, remark)=(select b.name, b.remark from TB b where b.id=a.id)   where exists(select 1 from TB b where b.id=a.

資料庫sql 建立刪除 增加 刪除操作

下面是Sql Server 和 Access 操作資料庫結構的常用Sql,希望對你有所幫助。 新建表: create table [表名] ( [自動編號欄位] int IDENTITY (1,1) PRIMARY KEY , [欄位1] nVarChar(50) default \'預設值\'

SQL 操作結構(建立刪除,修改

新增欄位: ALTER TABLE [表名] ADD [欄位名] NVARCHAR (50) NULL 刪除欄位: ALTER TABLE [表名] DROP COLUMN [欄位名] 修改欄位: ALTER TABLE [表名] ALTER COLUMN [欄位名] N

資料庫中某個中的某個的值是用逗號隔開的多個值,根據逗號拆分從另一個中查出資料返回

有兩個表A,B,表結構如下: A表 B表 關聯關係說明如下: (1)A.hospital_catalog=B.id (2)A表中hospital_catalog欄位的值是以 逗號 “,” 隔開,且兩邊用中括號“[ ]”包起,

SQL server 2008 新增刪除

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!        

SQL Server——資料管理(的資料型別、臨時、設定標識、使用預設值、建立約束、修改

目錄   一、欄位的資料型別——例項: 二、臨時表 三、設定標識欄位  四、使用預設值 五、建立約束 六、修改表 一、欄位的資料型別——例項: 建立一個新表(如圖)  當然我們也可以就所設計的表進行修改: