关闭 x
IT技术网
    技 采 号
    ITJS.cn - 技术改变世界
    • 实用工具
    • 菜鸟教程
    IT采购网 中国存储网 科技号 CIO智库

    IT技术网

    IT采购网
    • 首页
    • 行业资讯
    • 系统运维
      • 操作系统
        • Windows
        • Linux
        • Mac OS
      • 数据库
        • MySQL
        • Oracle
        • SQL Server
      • 网站建设
    • 人工智能
    • 半导体芯片
    • 笔记本电脑
    • 智能手机
    • 智能汽车
    • 编程语言
    IT技术网 - ITJS.CN
    首页 » SQL Server »SQL Server学习笔记之一对多的删除问题(1)

    SQL Server学习笔记之一对多的删除问题(1)

    2010-07-07 08:33:00 出处:ITJS
    分享

    以下的文章主要描述的是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))

    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学习笔记之一对多的删除问题,假如你对其实际相关操作有兴趣了解的话,下面的文章你一定不要错过,望你在浏览完此篇文章之后会对你在今后的学习中有更好的了解。

    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))

    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学习笔记之一对多的删除问题的介绍,望你能有所收获。 

    上一篇返回首页 下一篇

    声明: 此文观点不代表本站立场;转载务必保留本文链接;版权疑问请联系我们。

    别人在看

    帝国CMS7.5编辑器上传图片取消宽高的三种方法

    帝国cms如何自动生成缩略图的实现方法

    Windows 12即将到来,将彻底改变人机交互

    帝国CMS 7.5忘记登陆账号密码怎么办?可以phpmyadmin中重置管理员密码

    帝国CMS 7.5 后台编辑器换行,修改回车键br换行为p标签

    Windows 11 版本与 Windows 10比较,新功能一览

    Windows 11激活产品密钥收集及专业版激活方法

    如何从 Windows 11 中完全删除/卸载 OneNote?无解!

    抖音安全与信任开放日:揭秘推荐算法,告别单一标签依赖

    ultraedit编辑器打开文件时,总是提示是否转换为DOS格式,如何关闭?

    IT头条

    华为Pura80系列新机预热,余承东力赞其复杂光线下的视频拍摄实力

    01:28

    阿里千问3开源首战告捷:全球下载破千万,国产AI模型崛起新高度!

    01:22

    DeepSeek R1小版本试升级:网友实测编程能力已达到国际一线水平

    23:15

    NVIDIA 与 Dell 合作,大规模交付 Blackwell AI 系统

    20:52

    Cerebras 以最快的 Llama 4 Maverick 性能引领 LLM 推理竞赛

    20:51

    技术热点

    PHP中的随机性——你觉得自己幸运吗?

    搞定Ubuntu Linux下WPA无线上网

    Java使用内存映射实现大文件的上传

    MySQL安全性指南

    MySQL两项性能的基本测试浅谈

    教您使用UniqueIdentifier选取SQL Server主键

      友情链接:
    • IT采购网
    • 科技号
    • 中国存储网
    • 存储网
    • 半导体联盟
    • 医疗软件网
    • 软件中国
    • ITbrand
    • 采购中国
    • CIO智库
    • 考研题库
    • 法务网
    • AI工具网
    • 电子芯片网
    • 安全库
    • 隐私保护
    • 版权申明
    • 联系我们
    IT技术网 版权所有 © 2020-2025,京ICP备14047533号-20,Power by OK设计网

    在上方输入关键词后,回车键 开始搜索。Esc键 取消该搜索窗口。