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