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修改表結構 MySQL修改表結構操作命令總結 MySql資料庫在表中新增新欄位,設定主鍵,設定外來鍵,欄位移動位置,以及修改資料庫後如何進行部署和維護的總結 mysql 如何修改、新增、刪除表主鍵
MySQL修改表結構操作命令總結 以下內容轉自:http://www.jb51.net/article/58079.htm 表的結構如下: 複製程式碼程式碼如下:
mysql將一個表的資料插入到另外一個表,如果某個欄位已經存在將不插入的sql
insert into registerInfo_extend (userId,name) select userId,'遊客' from registerInfo where not exists (
建立帶有lob欄位的表or 新增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——資料表管理(欄位的資料型別、臨時表、設定標識欄位、使用預設值、建立約束、修改表)
目錄 一、欄位的資料型別——例項: 二、臨時表 三、設定標識欄位 四、使用預設值 五、建立約束 六、修改表 一、欄位的資料型別——例項: 建立一個新表(如圖) 當然我們也可以就所設計的表進行修改: