SQL Server學(xué)習(xí)筆記之一對(duì)多的刪除問題
以下的文章主要描述的是SQL Server學(xué)習(xí)筆記之一對(duì)多的刪除問題,假如你對(duì)其實(shí)際相關(guān)操作有興趣了解的話,下面的文章你一定不要錯(cuò)過,望你在瀏覽完此篇文章之后會(huì)對(duì)你在今后的學(xué)習(xí)中有更好的了解。
Hibernate能支持MS SQL7.0嗎?
Hibernate深度探險(xiǎn)!!----原創(chuàng)!
推薦圈子: Database圈子
更多相關(guān)推薦
1、create database school 創(chuàng)建數(shù)據(jù)庫(kù)school
2、drop database school 刪除數(shù)據(jù)庫(kù)school
3、use school 連接到school數(shù)據(jù)庫(kù),使其成為當(dāng)前數(shù)據(jù)庫(kù)
4、create table class(classID int primary key identity not null)
創(chuàng)建一個(gè)名為class的表,其有一個(gè)int型數(shù)據(jù)classID字段,該字段設(shè)置了主鍵約束
SQL Server學(xué)習(xí)筆記之并自動(dòng)編號(hào)列且不能為空
5、select * from class 查詢class表中的所有字段
6、drop table class 刪除class表
7、select * into class2 from class
將class表中的所有數(shù)據(jù)復(fù)制到class2表中
8、select * into class2 from class where 1=0 只復(fù)制表結(jié)構(gòu)
9、insert into class2(className) values('Juhn')或
insert into class2(className,tel) values('Bile','0731-2255664')
在class2表中插入一條記錄
10、delete from class2 where classID=2
刪除class2表中classID為2的行,如果指定where條件將刪除所有的行
delete from Student where StudentID between 13 and 15
刪除Student表中StudentID在13至15之間的數(shù)據(jù)(包括13和15)
11、alter table class2 add tel varchar(15) default('沒有電話')
修改表class2,為它添加一個(gè)tel列并將其默認(rèn)值設(shè)為'沒有電話'
12、alter table class2 drop column tel 刪除列
13、alter table student add constraint telDefault default('沒有電話') for tel
SQL Server學(xué)習(xí)筆記之修改tel列的默認(rèn)值
14、create table class3(classID int ,constraint id_key primary key(classID))
創(chuàng)建一個(gè)名為class3的表并為它設(shè)置了名為id_key的主鍵約束
15、unique 唯一約束
16、alter table class2 add age int check (age between 0 and 120)
為class2添一個(gè)age列,并為其設(shè)置檢查約束,使其的取值在0到120之間
17、alter table class2 add age int ,constraint ageCheck check
(age between 0 and 120)
其設(shè)置檢查約束方法二,為約束取名為ageCheck
18、alter table class2 add tel varchar(15) ,check
(tel like '[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9]')
其設(shè)置檢查約束方法三,此為模糊約束
19、create table class3(ID int primary key identity,classID int ,
name varchar(15) ,constraint classID foreign key(classID) references
class2(classID)) #p#
SQL Server學(xué)習(xí)筆記之設(shè)置外鍵約束
20、alter table class3 drop classID
刪除class3的classID外鍵約束
21、create index class2Name on class2(className)
在class2表的calssName字段上創(chuàng)建一個(gè)class2Name的索引
22、create unique index class2Name on class2(className)
SQL Server學(xué)習(xí)筆記之創(chuàng)建唯一索引
23、select classID,className from class2 where className='body'
select classID,className from class2 where className like '%s'
創(chuàng)建索引后查詢的的速度將更快,但會(huì)降低insert、update、delete的執(zhí)行速度
24、drop index class2.class2Name 刪除表class2上的class2Name索引
25、update class2 set className='Lida',tel='13787277732' where classID=3
將class2表中className和tel列、classID=3
行的單元格的值改為'Lida'和'13787277732',注意忽略where語句將改變表中所有的行
26、create default sexDefault as '男'; 創(chuàng)建一個(gè)名為sexDefault的默認(rèn)值
sp_bindefault sexDefault,'student.sex';
將創(chuàng)建的sexDefault默認(rèn)值綁定到student表的sex字段上
27、insert into class2(name,names) select name,names from class1
將class1中的數(shù)據(jù)全部復(fù)制到class2中
28、truncate table class 刪除class表中所有的行
29、select Name 國(guó)家,Population 人口 from BBC where Name
in('France','Cermany','Italy United')
查詢BBC表中'France','Cermany','Italy United'三個(gè)地區(qū)的所在的國(guó)家和人口數(shù)
30、select Name 國(guó)家 from BBC where Name like '%United%'
查詢BBC表中的Name字段中包含United字符的國(guó)家,通配符"_"表示匹配任意單個(gè)字符
30、select Name 國(guó)家, Population 人口 from BBC where Population>100000000 order by Population desc
查詢BBC表中的Population字段大于100000000的國(guó)家和人口,并按降序排序,默認(rèn)為升序asc
31、select Name,round(Population/1000000,0) as '人口(百萬)' from BBC where Region='South Asia'
查詢BBC表中的Region='South Asia'國(guó)家和百萬人口數(shù)(round是四舍五入)
32、select distinct Region from BBC
查詢BBC表中的Region字段中的非重復(fù)數(shù)據(jù),distinct排除重復(fù)數(shù)據(jù)
如有多列則作用在列的組合上,而不再作用在單列上
33、select top 50 percent * from BBC
查詢BBC表中的所有字段,但只返回總行數(shù)的50%,percent表百分?jǐn)?shù)、可選
34、select * from BBC where Area>100 and not GDP<10000000
查詢BBC表中的所有Area小于100并且GDP不小于10000000的數(shù)據(jù),會(huì)返回所有的列,不只是Area列
33、select * from BBC where Area not between 20000 and 30000
查詢BBC表中的所有Area不在20000和30000之間的數(shù)據(jù),會(huì)返回所有的列,不只是Area列
34、select distinct Name+str(Age) 學(xué)生 from Student
查詢Student表中Name和Age字段都不重復(fù)的數(shù)據(jù)
str(Age)返回Age的字符串表達(dá)形式,"學(xué)生"是別名
35、select * from Student where Nealth is null
查詢Student表中Nealth字段為null的數(shù)據(jù)
36、exec sp_helpconstraint 'Teacher'
SQL Server學(xué)習(xí)筆記之查看'Teacher'表中的所有約束
37、select * from Student where StudentID=1
for xml raw
返回XML語句
38、drop procedure MyProcedure
刪除一個(gè)存在的存儲(chǔ)過程
39、create procedure insert_Procedure
@Name varchar(10),
@Sex varchar(2),
@Age int,
@Tel varchar(20),
@Address varchar(50)
as
insert into student(Name,Sex,Age,Tel,Address) values(@Name,@Sex,@Age,@Tel,@Address)
創(chuàng)建一個(gè)插入數(shù)據(jù)的存儲(chǔ)過程
40、select datediff(day,'20090403',getdate())
用指定時(shí)間減去當(dāng)前時(shí)間,返回的是天數(shù),還可以用month返回月數(shù)
以上的相關(guān)內(nèi)容就是對(duì)SQL Server學(xué)習(xí)筆記之一對(duì)多的刪除問題的介紹,望你能有所收獲。
【編輯推薦】
- 實(shí)現(xiàn)SQL Server視圖的代碼有哪些?
- 實(shí)現(xiàn)SQL Server索引的代碼示例
- SQL Server創(chuàng)建約束的代碼運(yùn)用
- SQL Server創(chuàng)建表所要用到的代碼
- SQL Server 2005商業(yè)智能功能淺析