‘ SQL’ Archives

FOR XML PATH应用

今天要做个3个表的多对多的查询,搞了半天都实现不了我要的效果,后来经人提点知道了SQL存储过程中还有个FOR XML PATH的应用,下面是我在网上找到的资料,最后一个就是我要的效果。

DECLARE @TempTable table(UserID int , UserName nvarchar(50));
insert into @TempTable (UserID,UserName) values (1,’a')
insert into @TempTable (UserID,UserName) values (2,’b')
 
select UserID,UserName from @TempTable FOR XML PATH

运行这段脚本,将生成如下结果:
Read More »

MS-SQL表常用操作命令

新建表:
create table [表名]
(
[自动编号字段] int IDENTITY (1,1) PRIMARY KEY ,
[字段1] nVarChar(50) default ‘默认值’ null ,
[字段2] ntext null ,
[字段3] datetime,
[字段4] money null ,
[字段5] int default 0,
[字段6] Decimal (12,4) default 0,
[字段7] image null ,
)

删除表:
Drop table [表名]

插入数据:
INSERT INTO [表名] (字段1,字段2) VALUES (100,’51WINDOWS.NET’)


Read More »

关于本人

本人虎子,今年24,正好本命年

分类