SQL Pivot & UnPivot
create table students (
name varchar(25),
class varchar(25),
grade int
)
insert into students values ('张三','语文',20)
insert into students values ('张三','数学',90)
insert into students values ('张三','英语',50)
insert into students values ('李四','语文',81)
insert into students values ('李四','数学',60)
insert into students values ('李四','英语',90)
select * from students
pivot(
max(grade)
FOR [class] IN ([语文],[数学],[英语])
) AS pvt
/*
李四 81 60 90
张三 20 90 50
*/
--=========================================================================
create table students (
name varchar(25),
语文 int,
数学 int,
英语 int
)
GO
INSERT INTO students values ('李四',81,60,90)
INSERT INTO students values ('张三',20,90,50)
select *
from
students
unpivot
(
grade
for class in
([语文],[数学],[英语])
) AS upvt
/*
李四 81 语文
李四 60 数学
李四 90 英语
张三 20 语文
张三 90 数学
张三 50 英语
*/
相关文档:
http://www.cnblogs.com/dwjaissk/archive/2006/07/25/459476.aspx
增加字段
alter table docdsp add dspcode char(200)
删除字段
ALTER TABLE
table_NAME DROP COLUMN column_NAME
修改字段类型
ALTER TABLE table_name
ALTER COLUMN column_name new_data_type
改名
sp_rename
更改当前数据库中 ......
在windows XP SP3 中是可以安装 SQL Server 2005 的不会有兼容问题 我在安装的时候就什么问题都没看到 安装好后附加一个数据库 用Borland JBuilder 2006 Enterprise 和eclipse 也没问题
SQL2005 分五个版本,如下所列,
1.Enterprise(企业版),
2.Development(开发版),
3.Workgroup,(工作群版)
4.St ......
具体要注意的:
1.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索引而进行全表扫描,如:
select id from t where num is null
可以在num上设置默认值0,确保表中num列没有null值,然后这样查询:
select id from t where num=0 &n ......
//tree.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Syst ......