SQL-Server 创建数据库,创建表格

时间:2023-03-09 13:14:31
SQL-Server     创建数据库,创建表格
use master --使用master权限
create database E_Market--创建新数据库
on primary--指定主数据文件,有且只有一个
(
    name='E_Market_data',--主文件逻辑名称,_data指的是文件类型,这里是数据文件类型
    filename='f:\sql练习\E_Market_data.mdf'    ,
    --物理文件名,给出存储路径以及文件格式
    size=5MB,--文件初始大小
    filegrowth%--文件的增长率
)
log on--指定日志文件,至少有一个
(
    name='E_Market_log',--日志文件逻辑文件名,_log标明文件类型,这里是日志文件类型
    filename='f:\sql练习\E_Market_log.ldf',
    --日志文件物理文件名,存储路径,最后要标明格式。
    size=1MB,--初始大小
    maxsize=10MB,--最大值
    filegrowth=1MB--增长率
)
use E_Market
create table UserInfo--创建表格,表格名称为UserInfor
(--创建列的格式   列名+数据类型+[属性]
    UserID ) primary key,--primary key设置主键,主键默认不能为空
    UserPwd ) not null,
    UserName ) not null,
    Gender int not null
)
use E_Market
--增加列格式alter+table+表名+add+新建列名+数据类型
)
)
) not null

create table OrderInfo
(
    OrderID ,) primary key not null,--订单编号
    UserID ) not null,--会员账号
    CommodityID int not null,--商品编号
    Amount int not null,--数量
    PayMoney bigint not null,--付款金额
    PayWay ) not null,--付款方式
    Ordertime datetime not null,--订单日期
    Confirm int not null,--是否确认
    SendGoods int not null--是否发货
)

use E_Market
create table CommoditySort
(
--identity(1,1)设置标识列,自动增长,标识种子为1,自动增长1
    SortID ,) not null,--类别编号
    SortName ) not null--类别名称
)