USE db_sql2000
GO
--如果已存在表Sales,则删除此表
if exists (select * from dbo.sysobjects
where id = object_id(N'[dbo].[Sales]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Sales]
GO
--创建表Sales
CREATE TABLE Sales
(
sal_id uniqueidentifier NOT NULL
DEFAULT NEWID(),
book_code char(30) NOT NULL,
book_price money NOT NULL,
sal_num int NOT NULL default 1 ,
sal_tot as book_price * sal_num
)
GO
--向表中插入数据
INSERT Sales SELECT NEWID(),'ISBN 7-456-852',29,12
INSERT Sales SELECT NEWID(),'ISBN 857-7-357',19.5,10
INSERT Sales SELECT NEWID(),'ISBN 7-756-423',11,9
INSERT Sales SELECT NEWID(),'ISBN 873-7-964',32,15
GO
--随机返回2行数据
SELECT TOP 2 * FROM Sales
ORDER BY NEWID()
GO
GO
--如果已存在表Sales,则删除此表
if exists (select * from dbo.sysobjects
where id = object_id(N'[dbo].[Sales]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Sales]
GO
--创建表Sales
CREATE TABLE Sales
(
sal_id uniqueidentifier NOT NULL
DEFAULT NEWID(),
book_code char(30) NOT NULL,
book_price money NOT NULL,
sal_num int NOT NULL default 1 ,
sal_tot as book_price * sal_num
)
GO
--向表中插入数据
INSERT Sales SELECT NEWID(),'ISBN 7-456-852',29,12
INSERT Sales SELECT NEWID(),'ISBN 857-7-357',19.5,10
INSERT Sales SELECT NEWID(),'ISBN 7-756-423',11,9
INSERT Sales SELECT NEWID(),'ISBN 873-7-964',32,15
GO
--随机返回2行数据
SELECT TOP 2 * FROM Sales
ORDER BY NEWID()
GO