所謂主鍵,指的就是主關鍵字。在一個表中只能有唯一的一個主關鍵字。
“專業(yè)、務實、高效、創(chuàng)新、把客戶的事當成自己的事”是我們每一個人一直以來堅持追求的企業(yè)文化。 創(chuàng)新互聯(lián)是您可以信賴的網(wǎng)站建設服務商、專業(yè)的互聯(lián)網(wǎng)服務提供商! 專注于網(wǎng)站設計、成都網(wǎng)站制作、軟件開發(fā)、設計服務業(yè)務。我們始終堅持以客戶需求為導向,結合用戶體驗與視覺傳達,提供有針對性的項目解決方案,提供專業(yè)性的建議,創(chuàng)新互聯(lián)建站將不斷地超越自我,追逐市場,引領市場!
當你覺得需要定義多個主鍵時,多半是你對該表及其周邊關系的理解有誤。
if object_id('primarytbl') is not null drop table primarytblgo --建主表create table primarytbl( ID int primary key, --主鍵 aa int, bb int, cc int)go if object_id('foreigntbl') is not null drop table foreigntblgo --建外表create table foreigntbl( ID int primary key, --主鍵 aa int foreign key references primarytbl(ID) --建立外鍵 on update cascade, --更新級聯(lián) dd int, ee int)go --插入主表數(shù)據(jù)insert into primarytblselect 1, 1, 2, 3 union allselect 2, 2, 3, 4 union allselect 3, 3, 4, 5 union allselect 4, 4, 5, 6 union allselect 5, 5, 6, 7 union allselect 6, 6, 7, 8go --插入外表數(shù)據(jù)insert into foreigntblselect 1, 1, 2, 2 union allselect 2, 1, 3, 3 union allselect 3, 2, 4, 4 union allselect 4, 2, 4, 4 union allselect 5, 2, 5, 5 union allselect 6, 3, 6, 6 union allselect 7, 4, 7, 7go --顯示主外表信息select *from primarytbl select *from foreigntblgo--primarytbl/*ID aa bb cc----------- ----------- ----------- -----------1 1 2 32 2 3 43 3 4 54 4 5 65 5 6 76 6 7 8--foreigntblID aa dd ee----------- ----------- ----------- -----------1 1 2 22 1 3 33 2 4 44 2 4 45 2 5 56 3 6 67 4 7 7*/ --更新主表主鍵update primarytblset ID = 8where ID =1go --結果select *from primarytbl select *from foreigntblgo /*--primarytblID aa bb cc----------- ----------- ----------- -----------2 2 3 43 3 4 54 4 5 65 5 6 76 6 7 88 1 2 3--foreigntblID aa dd ee----------- ----------- ----------- -----------1 8 2 22 8 3 33 2 4 44 2 4 45 2 5 56 3 6 67 4 7 7*/ drop table foreigntbldrop table primarytbl
直接用SQL語句創(chuàng)建表時,將字段設置為自動編號主鍵就可以了。
dim cn as adodb.connection
dim sql as string
set cn=new adodb.connection
cn.open "driver={microsoft access driver (*.mdb)};uid=admin;pwd=;dbq=" app.path "\Access_db.mdb"
sql="'CREATE TABLE MyCustomers (CustID int IDENTITY (100,1) PRIMARY KEY, CompanyName nvarchar (50))"
cn.execute sql
set cn=nothing
一個可以設置主鍵,刪除唯一的主鍵,如delete
table
where
主鍵='"+鍵值+"',這樣每一行都有區(qū)分
還可以和控件綁定,如datagrid,可以用datagrid.currentrow來獲的當前行
第三種:可以用游標Enumerator,IEnumberator
objenum=dataview.GetEnumerator(),
row=(DataRowView)
objEnum.Current;
本文標題:vb.net設定主鍵 vb創(chuàng)建按鈕
標題URL:http://jinyejixie.com/article38/doscppp.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供域名注冊、小程序開發(fā)、品牌網(wǎng)站設計、網(wǎng)頁設計公司、標簽優(yōu)化、微信公眾號
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)