• SQL创建库、创建表


    常用的一些关键字:
    like  模糊查询
    and(between and) 和
    or (in(‘’,‘’))或

    between and XXX之间

    drop table TableName  --删除
    top x percent 百分之多少

    函数(count(*)多少条字段 sum求和 avg平均值  max 最大值 min最小值 )

    自增identity(1,1)
    主键 primary key
    不为空 not null
    默认 default
    唯一健 unique

    FOREIGN KEY (Id_P) REFERENCES Persons(Id_P)--外键

    --default 默认值

    check(len(字段)=3 )--约束  字符长度要等于三位  

    check (gender= '男'or gender= '女') ,--性别

    --创建数据库
    
    use master
    create database DB
    on(
    name='DB',
    filename='E:DB.mdf'
    )
    log on(
    name='DB_log',
    filename='E:DB_log.mdf'
    )
    --创建表
    use DB
    create table Table1(
    ID int identity(1,1)  primary key not null,--类型int  自增identity(1,1) 主键 primary key  不为空 not null
    name nvarchar(10) unique not null ,--类型nvarchar(10) 唯一健 非空    default默认
    age int not null ,
    sex nvarchar(2)
    )
    
    --向表内添加数据
    insert into Table1 values ('','19','')--单条添加
    insert into Table1
    select '','52','' union all   --union 连接
    select '','20','' union all
    select '','12','' union all
    select'','20',''             --多条添加
    --删除数据
    delete from Table1 where ID=2  --根据id删除
    --更新数据
    update  Table1 set name =''  where  ID=1   --根据id修改
    --查询数据
    select * from Table1--查询
    
    --方法二:
    
    --创建数据库  创建表同上
    create database[DB]
    go
    use [DB]  --选择到DB
    create table Table1(
    ID int identity(1,1)  primary key not null,--类型int    
    name nvarchar(10) unique not null default '未填写' ,--类型nvarchar(10)  非空  
    age int not null ,
    sex nvarchar(2)
    )
  • 相关阅读:
    二叉树中和为某一值的路径
    二叉搜索树的后序遍历序列(important!)
    从上往下打印二叉树
    最小的k个数(important!)
    扑克牌顺子
    栈的压入、弹出序列(important!)
    和为s的连续正数序列(important!)
    数组中只出现一次的数字
    fgets()函数以及fputs()函数
    C语言中的指针
  • 原文地址:https://www.cnblogs.com/zeng-qh/p/7128259.html
Copyright © 2020-2023  润新知