zoukankan      html  css  js  c++  java
  • 【SQL server基础】手动创建数据库和表格

    use master
    go
    if exists(select * from sysdatabases where name='learning')
        drop database learning
    go
    CREATE DATABASE learning
    ON
    (    NAME='learning_data',                        --主数据文件的逻辑名称
        FILENAME='E:SQLlearninglearning.mdf',        -- 主数据文件的物理名称
        SIZE=10MB,                                    --主数据文件的初始大小
        MAXSIZE=50MB,                                    -- 主数据文件增长的最大值
        FILEGROWTH=5%                                --主数据文件的增长率
     )
     --/*--日志文件的具体描述,各参数含义同上--*/
     LOG ON(
        NAME='learning_log',
        FILENAME='E:SQLlearninglearning.ldf',
        SIZE=5MB,
        MAXSIZE=25MB,
        FILEGROWTH=5MB)
    GO
    
    USE learning
    GO
    --在视图sysobjects中查找是否存在userInfo表格
    if exists(select * from dbo.sysobjects where name='userInfo')
        drop table userInfo
    GO
    --用户信息表格
    create table userInfo
    (
        userId                int not null,                --自增长ID
        userName            varchar(15) not null,        --用户姓名
        password            varchar(15) not null,        --用户密码
        email                varchar(25) not null,        --用户邮箱
        userRole            int,                        --用户角色(0:普通会员,1管理员)
        registerDate        varchar(25)                    --注册时间(默认当前时间)
    )
    --员工信息表格
    if exists(select * from sysobjects where name='employInfo')
        drop table employInfo
    GO
    create table employInfo
    (
        employId            int not null,            --自增长ID
        employNumber        varchar(15) not null,    --员工编号
        employPassword        varchar(15) not null,    --员工密码(默认6个8)
        employRealName        varchar(15) not null,    --员工真实姓名
        employPhoneNum        varchar(15) not null    --员工联系电话
    
    )
    
    --员工业绩表格
    if exists(select * from dbo.sysobjects where name='employResult')
        drop table employResult
    GO
    create table employResult
    (
        employResultId            int not null,                --自增长ID
        employResultNum            varchar(15) not null,        --业绩编号
        employNumber            varchar(15) not null,        --员工编号
        houseNumber                varchar(15) not null,        --房屋编号
        houseAmount                float,                        --房屋售价/出租价
        percentPaid                float,                        --提成比例(20%提成)
        salesCompleted            varchar(15),                --销售完成时间
    )
    
    --房屋信息表格
    if exists(select * from dbo.sysobjects where name='houseInfo')  
        drop table houseInfo  
    GO  
    create table houseInfo(  
        houseId                 int not null,               --自增长ID  
        houseNumber             varchar(15) not null,       --房屋编号  
        userName                varchar(15) not null,       --房屋发布会员  
        employNumber            varchar(15) not null,       --房屋对应负责销售员工编号(唯一主键)  
        informationType         int not null,               --判断是发布出租/出售房屋类型(0代表发布出租信息,1代表发布出售信息)  
        houseOwnerName          varchar(15) not null,       --业主姓名  
        houseOwnerSex           int not null,               --业主性别(0:代表男,1:代表女)  
        houseOwnerPhoneNumber   varchar(15),                --联系电话  
        houseArea               varchar(15) not null,       --房屋所在区域  
        houseSize               int not null,               --房屋面积  
        houseFloor              int,                        --房屋出租/出售 楼层  
        houseTotalFloor         int,                        --房屋总楼层数  
        HouseUnit               varchar(15),                --房屋户型(一室一厅,二室一厅,)[数据存储值为:一室二厅]  
        BudgetPrice             float,                      --预算价格  
        SpecificAddress         varchar(200) not null,      --房屋具体地址  
        houseFloorType          int not null,               --楼型,,[0:代表高层,1:代表多层,2:平房,3:其他]  
        otherRequirements       varchar(200)                --其他信息  
    )  
      
    --房产资讯表格
    
    if exists(select * from dbo.sysobjects where name='houseNews')  
        drop table houseNews  
    GO  
    create table houseNews(  
        houseNewId          int not null,                   --自增长ID  
        houseNewTheme       varchar(200) not null,          --咨询主题  
        houseNewContent     text,                           --咨询内容  
        houseNewDate        varchar(15)                     --发布日期  
    )  
    
    --留言评论表  
    if exists(select * from dbo.sysobjects where name='Message')  
        drop table Message  
    GO  
    create table Message(  
        messageId           int not null,                   --自增长ID  
        houseNumber         varchar(15) not null,           --房屋出租/出售编号(针对房屋编号留言)  
        messageContent      varchar(200) not null,          --留言内容  
        contact             varchar(50),                    --联系方式  
        messageDate         varchar(15) not null            --留言时间  
    )  
    
    --添加约束
    alter table userInfo add constraint pk_userId primary key(userId);
    alter table userInfo add constraint DF_userRole default(0)for userRole;
    alter table userInfo add constraint DF_registerDate default(CONVERT(varchar(100),GETDATE(),22)) for registerDate;
    
    
    alter table houseInfo add constraint pk_houseId primary key(houseId);
    
    alter table employInfo add constraint pk_employInfo primary key(employId);
    alter table employInfo add constraint DF_employPassword default('888888')for employPassword;
    
    alter table employResult add constraint pk_employResult primary key(employResultId);
    
    alter table houseNews add constraint pk_houseNewId primary key(houseNewId);
    alter table houseNews add constraint DF_houseNewDate default(CONVERT(varchar(100),GETDATE(),22)) for houseNewDate;
    
    alter table T_Message add constraint pk_messageId primary key(messageId);
    alter table T_Message add constraint DF_messageDate default(CONVERT(varchar(100),GETDATE(),22))for messageDate;
    
    
    GO
  • 相关阅读:
    easy ui 常用控件配置
    oracel 查询语句
    .Net 取树形结构的数据
    Asp.Net Core File的操作
    js 页面技巧
    ASP.NET Core 文件上传
    ASP.NET EF实体主外键关系
    ASP.NET MVC 后台传值前端乱码解决方案 富文本Ueditor编辑
    手机访问网站自动跳转到手机版
    Ecshop布局参考图
  • 原文地址:https://www.cnblogs.com/888888CN/p/7325593.html
Copyright © 2011-2022 走看看