SQL创建数据库示例代码

SQL创建数据库示例代码

create   database  Test
go
Use  Test
go
create   table  dbo.AutoTestLog
(
  IsError 
bit ,
  Info 
varchar ( 2000 ),
  TestDate 
dateTime ,
  OP_user 
int ,
  GroupNO 
varchar ( 10 ),
  
[ ID ]   int   identity ( 1 , 1 primary   key  ,
  LedAddress 
int ,
  Serino 
varchar ( 30 )
)
go
create   table  dbo.BatchPlan
(
  BatchNo 
varchar ( 30 primary   key ,
  state 
varchar ( 30 ),
  ProductType 
varchar ( 50 ),
  jiqicount 
int
)
go
create   table  dbo.BatchPlandetail
(
  batchNo 
varchar ( 30 ) ,
  LedAddress 
int ,
  
Primary   key (batchNo,LedAddress)
)
go
create   table  dbo.CrustList
(
  CrustbarCode 
varchar ( 100 primary   key ,
  opUser 
int ,
  crustState 
varchar ( 100 ),
  OpTime 
dateTime ,
  SeriNo 
varchar ( 30 )
)
go
create   table  dbo.Departs
(
  
[ ID ]   int   primary   key ,
  Depart_Name 
varchar ( 50 )
)
go
create   table  dbo.Led
(
  Address 
int   primary   key
)
go
create   table  dbo.Logs
(
 
[ id ]   int   identity ( 1 , 1 primary   key ,
 Computer 
varchar ( 10 ),
 Mode_Name 
varchar ( 50 ),
 Operate 
varchar ( 50 ),
 OP_Date 
datetime ,
 OP_user 
int
)
go
create   table  dbo.MainBoard
(
 barCode 
varchar ( 100 primary   key ,
 OPUser 
int ,
 state 
varchar ( 100 not   null ,
 opTime 
datetime ,
 BoardID 
varchar ( 30 )
)
go
create   table  dbo.Maintains
(
 
[ id ]   int   identity ( 1 , 1 primary   key ,
 Product_ID 
varchar ( 10 ),
 Problems 
varchar ( 50 ),
 isIn 
bit ,
 op_date 
datetime ,
 op_User 
int
)
go
create   table  dbo.Product
(
 CrustBarCode 
varchar ( 30 not   null
 SeriNo 
varchar ( 30 not   null ,
 opUser 
int ,
 opTime 
datetime
)
go
create   table  dbo.ProductType
(
  Product_ID 
varchar ( 10 not   null ,
  Product_name 
varchar ( 50 )
)
go
create   table  dbo.Users
(
 
[ ID ]   int   identity ( 1 , 1 primary   key ,
 UserName 
varchar ( 20 ),
 
[ password ]   varchar ( 10 ),
 Depart_ID 
int
 rightClass 
int ,
 LastDate 
datetime
)
go
INSERT   INTO   [ dbo ] . [ Departs ] ( [ ID ] [ Depart_Name ] )
VALUES ( 1 , ' 测试 ' )
go
INSERT   INTO   [ dbo ] . [ Users ] [ UserName ] [ Password ] [ Depart_ID ] [ RightClass ] [ LastDate ] )
VALUES ' Test ' ' 123456 ' 1 3 Getdate ())
go
INSERT   INTO   [ dbo ] . [ ProductType ] ( [ Product_ID ] [ Product_Name ] )
select   ' 1 ' , ' 690 '
union   all
select   ' 2 ' , ' 890 '
union   all
select   ' 3 ' , ' 981 '
go

你可能感兴趣的:(SQL创建数据库示例代码)