日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

数据库的增删改查的一个例题

發(fā)布時(shí)間:2023/12/8 数据库 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数据库的增删改查的一个例题 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題目:(下面的照片)

use T_JiNeng2;--用地基本信息表 create table T_proj_info( proj_id int identity(1,1) not null, proj_name varchar(50) not null, proj_no varchar(5) not null, proj_type varchar(25) not null, tilth_state float not null, proj_kind varchar(25) not null, farm_tot float not null, approve_unit varchar(50) not null )--創(chuàng)建行政區(qū)基本信息表 create table T_canton_info( canton_id int identity(10,1) not null, proj_id int not null, canton_tot float not null, canton_no varchar(5) not null, canton_name varchar(50) not null, branch varchar(50) not null, remark text not null )--設(shè)置主鍵 constraint 約束 alter table T_proj_info add constraint PK_T_proj_info_proj_id primary key (proj_id)alter table T_canton_info add constraint PK_T_canton_info_canton_id primary key (canton_id)--在被引用表 ‘Student’ 中沒有與外鍵 ‘FK_S’ 中的引用列列表匹配的主鍵或候選鍵。問題原因: --可能的原因之一是主鍵前后定義的不一致。 --或者主表沒有主鍵 需要添加或者修改主鍵 --設(shè)置外鍵 foreign:外國的--外鍵 references:參照 --怎么定義外鍵 一定是主表中的主鍵作為外鍵 alter table T_canton_info add constraint FK_T_canton_info_T_proj_info_proj_id foreign key (proj_id) references T_proj_info(proj_id)--插入數(shù)據(jù) insert into T_proj_info values('燦氏集團(tuán)','1','建設(shè)用地',999999,'商用',1000,'中共中央人民代表大會(huì)') insert into T_proj_info values('燦氏集團(tuán)2','1','娛樂用地',999999,'娛樂',1001,'中共中央人民代表大會(huì)') insert into T_proj_info values('燦氏集團(tuán)3','1','建設(shè)用地',999999,'商用',1003,'中共中央人民代表大會(huì)') insert into T_proj_info values('燦氏集團(tuán)4','1','建設(shè)用地',999999,'商用',13001,'中共中央人民代表大會(huì)') insert into T_proj_info values('燦氏集團(tuán)4','2','建設(shè)用地',1200,'商用',13001,'中共中央人民代表大會(huì)')insert into T_canton_info values(16,142,'83100','星沙','長沙市國土資源局','我家的') insert into T_canton_info values(17,142,'83101','星沙','長沙市國土資源局','我家的') insert into T_canton_info values(18,143,'83102','星沙2','長沙市國土資源局','我家的')select * from T_proj_info; select * from T_canton_info;--?查詢出項(xiàng)目編號(hào)為“1”的建設(shè)用地基本信息; select * from T_proj_info where proj_no =1 and proj_type ='建設(shè)用地'--?查詢出行政直屬部門為“長沙市國土資源局”的建設(shè)用地基本信息; select * from T_canton_info where branch='長沙市國土資源局'--?查詢出所有的建設(shè)土地基本信息并按農(nóng)用地總面積升序排序;asc 升序 desc降序 select * from T_proj_info where proj_type ='建設(shè)用地' order by farm_tot asc--?刪除耕地面積大于“1300”的建設(shè)用地基本信息; delete from T_proj_info where tilth_state<=1300--?請把直屬部門由“長沙市國土資源局”修改為“株洲市國土資源局”; update T_canton_info set branch='株洲市國土資源局' where branch='長沙市國土資源局'--單表視圖 --?創(chuàng)建名為ProjInfo_view1的視圖,視圖的數(shù)據(jù)為編號(hào)是“1”的建設(shè)用地基本信息; create view ProjInfo_view1 as select *from T_proj_info where proj_no='1'--刪除上題中所創(chuàng)建的ProjInfo_view1視圖 drop view ProjInfo_view1--查詢行政區(qū)名稱為‘星沙’的用地基本信息 select a.* from T_proj_info a inner join T_canton_info b on b.proj_id = a.proj_id where b.canton_name ='星沙'--使用內(nèi)連接連接兩張表中有關(guān)聯(lián)的數(shù)據(jù) (查詢所有兩個(gè)表中有關(guān)聯(lián)的數(shù)據(jù)) select * from T_proj_info a inner join T_canton_info b on b.proj_id = a.proj_id--使用內(nèi)連接查詢兩張表中行政區(qū)為星沙的數(shù)據(jù)。 select * from T_proj_info a inner join T_canton_info b on b.proj_id = a.proj_id where b.canton_name ='星沙'--left join:左連接 create view Plot_id_view2 as select T_plot_info.purpose,T_appr_area.* from T_plot_info left join T_appr_area on T_plot_info.proj_id = T_appr_area.proj_id

總結(jié)

以上是生活随笔為你收集整理的数据库的增删改查的一个例题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。