创建数据库、创建表

  1. Use master
  2. go
  3. If Exists (Select * From sysdatabases Where name = 'bbs') --检查是否以存在bbsDB数据库
  4.     Drop Database bbs
  5. go
  6. /*---- 创建文件夹 ----*/
  7. --sql 2005如何使用被禁止的"xp_cmdshell"
  8. USE master 
  9. EXEC sp_configure 'show advanced options', 1 
  10. RECONFIGURE WITH OVERRIDE 
  11. EXEC sp_configure 'xp_cmdshell', 1 
  12. RECONFIGURE WITH OVERRIDE 
  13. EXEC sp_configure  'show advanced options', 0 
  14. go
  15. Exec xp_cmdshell 'mkdir D:/bbsDB' --调用DOS命令创建文件夹
  16. go
  17. /*------   建库   ------*/
  18. Create Database bbs
  19. on
  20. (
  21.     /*--------  数据文件具体描述   ----------*/
  22.     Name = 'bbs_data',                  --主数据文件的逻辑名称
  23.     FileName = 'D:/bbsDB/bbs_data.mdf', --数据文件的物理名称
  24.     Size = 5Mb,                         -- 主数据文件的初始大小
  25.     FileGrowth = 20%                    --主数据文件增长率
  26. )
  27. log on
  28. (
  29.     /* ------ 日志文件的具体描述,各参数含义同上 ------ */
  30.     Name = 'bbs_log',
  31.     FileName = 'd:/bbsDB/bbs_log.ldf',
  32.     Size = 3Mb,
  33.     FileGrowth = 10%
  34. )
  35. go
  36. -----------------------------------------------
  37. /*--- 创建表 ---*/
  38. Use bbs
  39. go
  40. /* --- 检查是否存在表TBL_USER  ---*/
  41. If Exists (Select * From Sysobjects where name = 'TBL_USER')
  42.     Drop Table TBL_USER
  43. Create Table TBL_USER
  44. (
  45.     uId int primary key identity(1,1),   --主键,标识列
  46.     uName varchar(20) Unique(uName) not null,
  47.     uPass varchar(20) not null,
  48.     head varchar(100) not null,
  49.     regTime dateTime not null,
  50.     gender smallint not null
  51. )
  52. go

你可能感兴趣的:(创建数据库、创建表)