|
发表于 30-11-2010 01:27 AM
|
显示全部楼层
MSSQL:
忘了说明 memberID 是 Identity Column。
要确定 table 有没有 Identity Column 就要这样:
if exists(
SELECT name
FROM sys.columns
WHERE [object_id] = object_id(N'table') and is_identity = 1
)
Begin
Print N'identity column already exist'
End
else
Begin
Print N'Need to add identity column'
End
如果没有 Identity Column 就要create 新的 table2(当成Temp Table)把 table data insert 到 table2,然后:
ALTER TABLE Table2
ADD [memberID] INT IDENTITY(1,1)
要 list 出所有的 Data 就要这样做:
declare @abc1 nvarchar(max),
@abc2 nvarchar(max)
set @abc1 = (select MIN(memberID) from table)
set @abc2 = (select Max(memberID) from table)
select * from table where memberID = @abc1 or memberID = @abc2
MYSQL:
基本上和MYSQL做法没差。
(SELECT min(memberID) from table)
UNION
(SELECT max(memberID) from table) |
|