zoukankan      html  css  js  c++  java
  • sqlserver库相关-表相关-3

    原文:

    https://www.cnblogs.com/wlx520/p/4684441.html

    库相关

    建库

    --创建School数据库之前:首先判断数据库是否存在,若存在则删除后再创建,若不存在则创建--
    --exists关键字:括号里边能查询到数据则返回‘true’ 否则返回‘false’
    if exists(select * from sysdatabases where name = 'School')
    --exists返回‘true’则执行删除数据库操作--
    drop database School

    --exists返回‘false’则表明数据库不存在,直接创建
    create database School
    on primary
    (
    --主数据库文件--
    name = 'School', --主数据文件逻辑名
    fileName = 'D:projectSchool.mdf', --主数据文件物理逻辑名
    size = 5MB, --初始值大小
    maxsize = 100MB, --最大大小
    filegrowth = 15% --数据文件增长量
    )
    log on
    (
    --日志文件--
    name = 'School_log',
    filename = 'D:projectSchool_log.ldf',
    size = 2MB,
    filegrowth = 1MB
    )
    go

    查看有哪些库

    select * from sysdatabases

    删除库

    drop database School

    表相关

    创建表

    --1、选择操作的数据库--
    use School
    go

    --判断表是否存在--
    if exists(select * from sysobjects where name = 'Student')
    drop table Student

    --2、创建表---
    create table Student
    (
    --具体的列名 数据类型 列的特征(是否为空)--
    StudentNo int identity(2,1) not null,
    LoginPwd nvarchar(20) not null,
    StudentName nvarchar(20) not null,
    Sex int not null,
    GradeId int not null,
    phone nvarchar(50) not null,
    BornDate datetime not null,
    Address nvarchar(255),
    Email nvarchar(50),
    IDENTITYcard varchar(18)
    )
    go

    查看有哪些表

    ---查看所有数据库对象(数据库表)---
    select * from sysobjects

    写入表数据

    insert into student(name) values('s1');

    删除表

    drop table Student

  • 相关阅读:
    WordPress使用记录
    Sql Server数据库的存储过程
    (一)vs2010 新建、使用dll
    Commons Betwixt : Turning beans into XML
    error: failed to attach to process ID 0
    java中常用的内存区域
    计算N阶乘中结尾有多少零
    计算出两个日期相隔多少天
    Cognos Active Report 时间区间选择的解决办法
    PHP heredoc 用法
  • 原文地址:https://www.cnblogs.com/hanxiaohui/p/9570708.html
Copyright © 2011-2022 走看看