![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
SQL
文章平均质量分 61
高大王
一阵凉意袭来,说明又该过年
展开
-
SQL Server 两个数据库将数据库中表A 中的数据修改到表B中
update [数据库名B].dbo.[表名] set [修改的字段] =(select [数据库名A].dbo.[表名].[字段名] from [数据库A].dbo.[表名] where [数据库名A].dbo.[表名].[ID] = [数据库名B].dbo.[表名].[ID] ) 两个ID是对应的原创 2021-09-25 13:01:08 · 1398 阅读 · 0 评论 -
SQL 操作3
–select Grade.GradeName,1,Id*2 –from Grade –别名 三种用法 – 別名=值 2.值 as 别名 3.值 别名 select Grade.GradeName,数字 = 1,Id2 as 编号,Id3 编号2 from Grade –排序 – Order By --asc --desc降序 – top 获取部分数据 –select top 2* from class –分页获取数据 select top 2 * from Class where Id原创 2021-09-16 09:35:29 · 153 阅读 · 0 评论 -
SQL Server数据库操作
数据库拷贝 1.选择-任务-分离-勾上删除连接 --这时候数据库就不见了 2.在数据库-选择附加–添加–数据库(如何报错没有权限,在数据库的当前文件夹下选择-属性-点击安全-添加一个Everyone -完全控制) 也是可以使用脱机与联机 这样更方便 –获取列的类型 –select a.name as [column],b.name as type –from syscolumns a,systypes b –where a.id=object_id(‘FoodMaterialInfo’) and a.xt原创 2021-09-09 14:29:44 · 128 阅读 · 0 评论 -
SQL Server 数据库操作
–use master –go –if(exists(select * from sysdatabases where name=‘mydb2’)) --判断是否有这个数据库 – drop database mydb2 --删除数据库 –create database mydb2 --创建数据库 –go –use mydb2 –go – primary key 主键 –identity(1,1) 标识列只能在整型上使用,只读的不允许修改(种子,增量) –not null 不允许为空 –uniqu原创 2021-09-08 12:20:39 · 80 阅读 · 0 评论 -
SQL必知必会19-22
–19储存过程 –create PROCEDURE MailingListCount as –Declare @cnt integer –select @cnt=COUNT(*) –from Customers –where Not cust_email is null; –return @cnt –调用存储过程 –Declare @ReturnValue int –execute @ReturnValue=MailingListCount; –select @ReturnValue; –例子在Oreder原创 2021-09-04 17:18:02 · 121 阅读 · 0 评论 -
SQL必知必会 15-18
15章 –插入行 into 关键字是可选的 –insert into Customers –values (‘10006’,‘Toy Land’,‘123 Any Street’,‘New York’,‘NY’,‘11111’,‘China’,null,null) –小心使用VALUES –不管使用哪种INSERT语法,VALUES的数目都必须正确。 如果不提供列名,则必须给每个表列提供一个值;如果提供列名,则必须给列出的每个列一个值。否则,就会产生一条错误消息, –相应的行不能成功插入。 –插入行2 –原创 2021-09-04 14:32:56 · 116 阅读 · 0 评论 -
SQL 必知必会10-14
10章 –创建分组 查找列中id,重复次数 –select vend_id,count(*) as num_prods –from Products –group by vend_id –过滤分组 找出vend-id 重复大于2的数据 having 过滤分组 –select vend_id,count() as num_prods –from Products –group by vend_id –having COUNT() >2 –select vend_id,COUNT() as num原创 2021-08-23 10:20:22 · 85 阅读 · 0 评论 -
SQL 必知必会5-9
5 select prod_id,prod_price,prod_name –from Products –where vend_id =‘1001’ or prod_price <=10 –//查看执行的数据,当执行 vend_id =‘1001’ or vend_id =‘1005’ and 就不执行了 –select prod_name,prod_price,vend_id –from Products –where vend_id =‘1001’ or vend_id =‘1005’ –a原创 2021-08-23 09:34:01 · 70 阅读 · 0 评论