在项目开发中遇到这么一个例子,首先产品表 tb_product ----------------------------- id    name 1     手机 2    电脑 3     笔记本 第二张表 tb_product_chain(产品链) ------------------------------------------------------ int   product_id     parent_product_id 1       1                    …
update table a, table b set a.filed1= b.field2, a.field2= b.field1where a.id = b.id…
sql一个表中两个字段,合并求和 SELECT SUM(字段a+'.'+字段b) as total  from TABLE…
SQL语句 在一个表中插入新字段: alter table 表名 add 字段名 字段类型 例: alter table OpenCourses add Audio varchar(50)alter table ListenCourses add Audio varchar(50)…
首先描述问题,student表中有字段startID,endID.garde表中的ID需要对应student表中的startID或者student表中的endID才能查出grade表中的name字段,这时候问题就来了,如果需要一条sql一句同时查出garde表中的两条数据怎么办?(两表的关联字段为 SID) sql="select b.name,c.name as name2 from student a,garde b,grade c where a.SID=b.SID and a.SID=c…
1,为当前已有的表添加新的字段 alter table student add studentName varchar(20) not null; 2,为当前已有的表中的字段设置为主键自增 alter table student add constraint PK_studentId primaryKey(studentId); 3,为当前已有的表中的字段设置为外键 alter table student add constraint FK_teacherId_studentInfo forei…
添加字段:alter table matInformation add facid varchar(99)  default ''; 导入数据:update matInformation m set facid=(select facid from material_register v where m.partNumber=v.partNumber);(参考:https://blog.csdn.net/mar_fuck/article/details/79460571) 遇到问题:ERROR…
研究了两天也没有研究的很明白,但是问题做出来了, 如下表中的字段,第一级是由逗号隔开字符串,第二级是由空格隔开的字符串,现在想取空格字符串中的第几个空格前后的字符串, 所用到的工具,1.是 for xml path(''), 2.是Stuff,必须和select 配合着使用哦这样,才能把字符串前面的字符去掉.和right的区别是设么?是stuff可以,在删除的位置可以插入新的字符串. 3.是一个函数f_split ALTER function [dbo].[f_split](@c varchar…
一.创建表 create table stuUnion ( sid int identity primary key, cid int, id ) ) 二.添加数据 insert into stuUnion ,'a' union ,'b' union ,'c' union ,'d' union ,'e' union ,'f' union ,'g' 三.用标量函数查询 ()创建标量函数 create function b(@cid int) ) as begin ) select @s=isnul…
SELECT o.name,o.object_id,c.name,c.column_id,c.collation_name   FROM sys.columns c      JOIN sys.objects o          ON c.object_id = o.object_id   WHERE o.object_id = OBJECT_ID('dbo.FileImportMapping')      AND c.name = 'OriginalFileId'…