--写一段SQL表示祝福
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Table_life]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Table_life]
GO
CREATE TABLE [dbo].[Table_life] (
[age] [int] NOT NULL ,
[Live_Status] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[Work_Status] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[Friend_Status] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[Earning_Status] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Table_life] WITH NOCHECK ADD
CONSTRAINT [PK_Table_life] PRIMARY KEY CLUSTERED
(
[age]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Table_life] WITH NOCHECK ADD
CONSTRAINT [DF_Table_life_Live_Status] DEFAULT ('') FOR [Live_Status],
CONSTRAINT [DF_Table_life_Work_Status] DEFAULT ('') FOR [Work_Status],
CONSTRAINT [DF_Table_life_Friend_Status] DEFAULT ('') FOR [Friend_Status],
CONSTRAINT [DF_Table_life_Earning_Status] DEFAULT ('') FOR [Earning_Status]
GO
declare @i int
set @i=1
while @i<=100
begin
if @i<20
begin
update Table_life set Live_Status='Happy',Work_Status='',Friend_Status='More',Earning_Status='' where age=@i
insert Table_life (age,Live_Status,Work_Status,Friend_Status,Earning_Status)
values (@i,'Happy','','More','')
end
else
begin
update Table_life set Live_Status='Happy',Work_Status='EnRich',Friend_Status='More',Earning_Status='More' where age=@i
insert Table_life (age,Live_Status,Work_Status,Friend_Status,Earning_Status)
values (@i,'Happy','EnRich','More','More')
end
set @i=@i+1
end
select * from Table_life