数据库建表

​use 选择现有数据库。(master为系统默认数据库)

use master 

go

if exists(select * from sys.databases where name = 'Student')

drop database Student

go

create database Student

go

use Student

go

create table StuInfo

(

 

        StuId int primary key identity(1,1),

StuName varchar(20) not null,

Age int not null,

Sex char(2) not null,

CellPhone char(11) not null,

[Address] varchar(50) not null

)

1、GO是批处理的标志,GO语句把程序分成一个个代码块,即使一个代码块执行错误,它后面的代码块任然会执行。

2、if exists 判断数据库中是否存在某元素

3、drop database Student: 删除Student数据库

4、create datebase Student :创建Student数据库

5、create table StuInfo :创建数据表StuInfo

6、primary key :StuInfo表的主键

7、identity : 主键自增

8、 char存储定长数据很方便,CHAR字段上的索引效率极高,比如定义手机号char(11),那么不论你存储的数据是否达到了11个字节,都要占去11个字节的空间。 

9、varchar存储变长数据,但存储效率没有CHAR高。如果一个字段可能的值是不固定长度的,我们只知道它不可能超过10个字符,把它定义为 VARCHAR(10)是最合算的

10、not null :非空约束 ,默认情况下列是可以接受 null 值,not null约束列不能接受null值

11、[Address]  :Address是系统默认的字段 , 如果需要用系统默认字段就要加上 [ ] 把该字段括起来

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值