日期:2014-05-18 浏览次数:20413 次
if exists (select * from dbo.sysobjects where id = object_id(N'[tb]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [tb] GO -- 示例数据 create table [tb]([id] int PRIMARY KEY,[pid] int,name nvarchar(20)) INSERT [tb] SELECT 1,0,N'中国' UNION ALL SELECT 2,0,N'美国' UNION ALL SELECT 3,0,N'加拿大' UNION ALL SELECT 4,1,N'北京' UNION ALL SELECT 5,1,N'上海' UNION ALL SELECT 6,1,N'江苏' UNION ALL SELECT 7,6,N'苏州' UNION ALL SELECT 8,7,N'常熟' UNION ALL SELECT 9,6,N'南京' UNION ALL SELECT 10,6,N'无锡' UNION ALL SELECT 11,2,N'纽约' UNION ALL SELECT 12,2,N'旧金山' GO
------解决方案--------------------
貌似笨狼出的面试题,呵呵