国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

ylb: 數據庫操作方法基礎

2024-07-21 02:49:03
字體:
來源:轉載
供稿:網友
ylb: 數據庫操作方法基礎
ylbtech-SQL Server:SQL Server-數據庫操作方法基礎

數據庫操作方法基礎。

ylb: 數據庫操作方法基礎 返回頂部
----------試圖操作(view)-----------------------創建視圖create view titles_viewasselect title,type from titles--調用視圖select * from titles_view--刪除視圖drop view titles_view--修改視圖alter view titles_viewasselect title,type,PRice from titlesgo--------對表(Table)的操作------------------create table teacher(number int primary key,name varchar(20) not null,sex char(2) check(sex='男' or sex='女'),birthday datetime,job_title varchar(20),salary money,memo ntext,nicheng varchar(20) unique,height numeric(7,2))select * from teacherdrop table studentcreate table Student(number int primary key,name varchar(20) not null,sex char(2) check(sex='男' or sex='女'),teachernumber int foreign key references teacher(number))--在 Student 表 添加一個新列alter table Studentadd birthday datetime,salary money--在 Student 表 刪除一個已有的列alter table Studentdrop column salary--在 Sutdent 表 修改一個列的約束alter table Studentalter column name varchar(20)insert Student(number,name,sex,teachernumber)values(0003,'小小黑2','男',1)insert Student(number,name,sex,teachernumber)values(0004,'小小黑4','男',1)--外鍵必須產生于主鍵--在刪除的時候,如果這表上的列在其他表有外鍵的話--(如果插入的數據產生關聯)必須先刪外鍵數據之后,才可以刪除這表的數據------------查詢技術use pubsgo--查詢書名表的所有列select * from titles--查詢書名表的書名編號、書名名稱、單價、類型select * from titlesselect title_id,title,price,type from titles--as 用法 取別名select title_id as '書名編號',title as '書名名稱',price as '單價',type as'類型' from titles--oder by 排序 asc,desc--查詢書名表的所有列 按價格排序(從大到小) ascselect title,price from titles order by priceselect title,price from titles order by price asc--查詢書名表的所有列 按價格排序(從小到大)descselect title,price from titles order by price desc---where 條件--查看書名編號為:BU1111的記錄信息select * from titlesselect * from titles where title_id='BU1111'--查看書的類型是"business"的所有信息select * from titles where type='business'-- in 包含-- not in 不包含-- or 或者-- and 且--查看書的類型是"business,mod_cook"的所有信息select title,type from titles where type='business' ortype='mod_cook'select title,type from titles where typein('business','mod_cook')--查看書的類型不是"business,mod_cook"的所有信息select title,type from titles where type!='business' andtype!='mod_cook'select title,[type] from titles where type notin('busines','mod_cook')--一些函數應用min,max,sum,avg,count,count(*)select * from titles--不算price 等于null----min 最小值select min(price) from titlesselect price from titles where type='business'select min(price) from titles where type='business' -----max 最大值select max(price) from titles----- sum 總和select sum(price) from titles-----avg 平均值select avg(price) from titles-----count(*),count(列明)select count(*) as '總計' from titlesselect count(title_id) '總計' from titles-- like  像select * from titles--查一下 title_id 中有'BU'的所有行數-----'%' 代表所有字符select * from titles where title_id like '%BU%'-----‘_’ 代表一個字符select * from titles where title_id like '__1%'--group by 分組select type,count(*) '記錄總數',min(price) '最小價格',max(price)'最大價格',sum(price) '總價格',avg(price) '平均價格' from titles group bytype--比較運算符=,>,<,>=,<=,!=----!= 不等于select title,price from titlesselect title,price from titles where price>10--any 任何一個,all 都select title,price from titleswhere price >any(select price from titles wheretype='business')select price from titles where type='business'select min(price) from titles where type='business'select title,price from titleswhere price >all(select price from titles wheretype='business')select max(price) from titles--exists 存在use mastergo-------對數據庫(Database)的操作---------------if exists(select * from sys.databaseswhere name='db2')begin drop database db2endgocreate database db2gouse db2 2011/2/17 ylb pm17:20
warn作者:ylbtech出處:http://ylbtech.cnblogs.com/本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 房产| 大安市| 乌海市| 高州市| 安乡县| 蒙山县| 海伦市| 宣汉县| 正安县| 盐山县| 扎兰屯市| 木里| 都兰县| 凤山市| 巴里| 南京市| 马鞍山市| 多伦县| 筠连县| 徐闻县| 白水县| 吉林市| 富宁县| 根河市| 如东县| 北碚区| 比如县| 西宁市| 青铜峡市| 根河市| 永登县| 库尔勒市| 和田县| 晋江市| 双桥区| 平利县| 马公市| 黔西| 克拉玛依市| 尖扎县| 罗甸县|