sql server create语句实例

数据库 SQL Server
在SQL语言中,create语句即可以创建数据库,也是可以创建表,是SQL语句中最重要也是最常用的语句,下面就将为您介绍一个使用create语句创建数据库的例子,供您参考。

sql server create语句用于创建数据库和表,下面就将为您介绍使用sql server create语句创建数据库的实例,供您参考,希望对您更深入了解sql server create语句有所帮助。

  1. use master --切换到master数据库   
  2. go   
  3. --检测是否存在同名的数据库   
  4. if exists(select 1 from sysdatabases where name = 'tour')   
  5. begin   
  6.   drop database tour   
  7. end   
  8. go   
  9. create database tour   
  10. on --数据文件   
  11. (   
  12.   name = 'tour_mdf', --数据文件逻辑名   
  13.   filename = 'D:\tour.mdf',--数据文件存放路径   
  14.   size = 1MB,--初始大小   
  15.   maxsize = 10MB,--最大大小   
  16.   filegrowth = 1MB--增长速度   
  17. )   
  18. log on --日志文件   
  19. (   
  20.   name = 'tour_ldf', --日志文件逻辑名   
  21.   filename = 'D:\tour.ldf',--日志文件存放路径   
  22.   size = 1MB,--初始大小   
  23.   maxsize = 10MB,--最大大小   
  24.   filegrowth = 1MB--增长速度   
  25. )   
  26. go   
  27. use tour   
  28. go   
  29. 创建数据库表   
  30. if exists(select * from sysobjects where name='stuInfo') drop table stuInfo   
  31. create table   stuInfo    /*-创建学员信息表-*/   
  32. (   
  33.  
  34. stuNo   varchar(6) not null unique,   --学号,非空(必填)   
  35. stuName  varchar(20) not null ,  --姓名,非空(必填)   
  36. stuAge  int  not null,  --年龄,INT类型默认为4个字节   
  37. stuID  NUMERIC(18,0),     --身份证号   
  38. stuSeat   int  IDENTITY (1,1),   --座位号,自动编号   
  39. stuAddress   text   --住址,允许为空,即可选输入   
  40. )   
  41. go   
  42.  
  43. if exists(select * from sysobjects where name='stuMarks') drop table stuMarks   
  44. create table  stuMarks   
  45. (   
  46. ExamNo  varchar(6)  not null foreign key references stuInfo(stuNo) ,  --考号   
  47. stuNo  varchar(6) not null,   --学号   
  48. writtenExam  int  not null,  --笔试成绩   
  49. LabExam  int  not null    --机试成绩   
  50. )   
  51. go   
  52.  
  53. if exists(select * from sysobjects where name='users') drop table users   
  54. create table users   
  55. (   
  56.     userID int not null primary key identity(1,1),   
  57.     userName varchar(255) not null unique,   
  58.     userPWD varchar(255) not null,   
  59.     userAge int,   
  60.     userBirthDay datetime,   
  61.     userEmail varchar(255)   
  62. )   
  63. go  

 

 

 

【编辑推荐】

强制关闭SQL Server数据库连接的方法

sql server字符串的类型

sql server字符串函数分类详解

sql server端口的更改方法

sql server日志文件过大的解决办法

责任编辑:段燃 来源: 互联网
相关推荐

2010-10-21 14:27:35

SQL Server时

2010-09-17 16:53:14

SQL中CREATE

2010-09-17 14:48:28

SQL条件语句

2010-09-07 11:24:25

SQL语句

2010-11-04 11:39:47

2010-09-26 10:08:43

sql条件语句

2010-09-07 11:33:04

SQL语句

2010-07-08 13:26:02

SQL Server

2010-07-08 13:32:22

SQL Server

2010-11-12 13:08:36

动态sql语句

2010-11-11 11:13:54

SQL Server

2010-10-21 12:16:11

SQL Server查

2010-10-19 16:06:26

SQL Server索

2010-09-28 14:06:43

Sql Server表

2010-09-06 13:34:37

Sql Server语句

2010-10-22 15:52:41

SQL Server创

2010-09-14 10:16:57

sql server

2010-09-03 10:40:30

SQL删除

2010-09-09 16:34:19

SQL循环while

2010-09-02 11:47:43

SQL删除
点赞
收藏

51CTO技术栈公众号