zoukankan      html  css  js  c++  java
  • SQL server数据类型、增删改查

    数据类型:

    整数型:bigint、int、smallint、mediumint、tinyint

    小数类型:decimal、numeric

    浮点型:real、float、double

    位型:bit

    字符型:char、varchar、longvarchar、longtext

    unicode字符型:nchar、nvarchar

    文本型:text、tinytext

    二进制型:binary、varbinary

    日期时间类型:date、time、datetime、timestamp、year

    Datetime   范围是:1753.1.1—— 9999.12.31

    Smalldatetime 范围是:1900.1.1 ——2079.6.6

    创建数据库:右击数据库,新建数据库,输入数据库的名称

    用语句创建

    create database fruit
    go

    使用数据库创建一个表,表中添加列名

    use fruit
    go
    create table fruit
    ( code int,
    name varchar(50),
    price decimal(18,2),
    chandi varchar(50))

    在表中添加数据并查询表:

    insert into fruit values(1,'苹果',2.5,'沂源')
    insert into fruit values(2,'香蕉',3.5,'海南')
    insert into fruit values(3,'鸭梨',2.5,'烟台')
    insert into fruit values(4,'葡萄',4.5,'浙江')
    insert into fruit values(5,'芒果',5.5,'广东')
    select * from fruit

    增删改查数据:

    查询数据:

    select * from fruit
    --查询所有
    select name from fruit
    --查询一列
    select name,chandi from fruit
    --查询多列,用逗号隔开
    select * from fruit where code=4
    --查询一整行,条件查询
    select name from fruit where code=2
    --查询编号为2的水果的名称
    select name,chandi from fruit where code=3
    --查询编号为3的水果的名称、产地

    增加数据:

    insert into fruit values (6,'荔枝',6.5,'湖南')
    insert into fruit(code,name,price) values (7,'菠萝',6)

    修改数据:

    update fruit set price=5 where code=4
    --将编号为4的水果的单价改为5
    update fruit set chandi='南京' where code=5
    --将编号为5的水果的产地改为南京

    删除数据:

    delete from fruit
    --全部删除
    delete from fruit where name='鸭梨'
    --删除名字为鸭梨的整行数据
  • 相关阅读:
    再读《赤壁赋》念《滕王阁序》
    赤壁赋
    关于C语言中的位域
    Eliot
    cnblogs.com博客园简介
    springboot+thymeleaf 实现图片文件上传及回显
    绑定事件的方式
    无法获得 VMCI 驱动程序的版本: 句柄无效。
    Connection is read-only解决方式
    Java 线程的 5 种状态
  • 原文地址:https://www.cnblogs.com/wy1992/p/6065780.html
Copyright © 2011-2022 走看看