您的位置:首页 - SQL Server
SQL代码创建删除清空表
创建表

--用户表  
  if exists (select * from sysobjects where name = 'Tse_User')
   drop table Tse_User
  Create table Tse_User
  (
   ID int identity(1,1),
   UserID int not null,
   UserName varchar(64) not null,
   RealName varchar(64) null,
   PRIMARY KEY (UserID)
  )


--产品表
  if exists (select * from sysobjects where name = 'Tse_Product')
   drop table Tse_Product
  Create table Tse_Product
  (
   ID INT IDENTITY(1,1),
   ProductID varchar(64) not null,
   ProductName varchar(256) not null,
   Price float not null,
   Storage int not null, --库存
   PRIMARY KEY(ProductID)
  )


--订单表
  if exists (select * from sysobjects where name = 'Tse_Order')
   drop table Tse_Order
  Create table Tse_Order
  (
   ID int identity(1,1),
   OrderID varchar(64) not null,
   UserID int not null,
   ProductID varchar(64) not null,
   Number int not null, --购买数量
   PostTime datetime not null,
   PRIMARY KEY(OrderID),
   FOREIGN KEY (UserID) REFERENCES Tse_User(UserID),
   FOREIGN KEY (ProductID) REFERENCES Tse_Product(ProductID)
  )


删除表

 drop table Tse_User


清空表

truncate table Tse_User 清除表中所有数据,下次插入编号从1开始
delete from Tse_User 清除表中所有数据,但下次插入编号从原有编号+1开始
本站导航
相关文章
柯乐义 Copyright© keleyi.com