zoukankan      html  css  js  c++  java
  • Server基本语句的用法

    1、创建数据库

    create database databaseName

    use databaseName

    go   /*  转到指定数据库 */

    2、创建表

    create table tableName(

    /*

    字段名

    */

    )

    3、插入数据

    insert into tableName values('','','','','',',',);  /* 括号里面是需要插入的数据 */

    4、创建主键

    alter table tableName add constra py_tableNameId primary key (tableNameId)   /*   py_tableNameId: 名称;tableNameId:需要设置的主键名*/

    5、添加外键

    alter table tableNameA add constra py_tableNameId foreign key (tableNameAId) references  tableNameB (tableNameBId) /*   py_tableNameId: 名称;tableNameAId:需要设置的外键名,tableNameBId:需要关联的字段名*/

    6:修改数据

    update tableName set 字段名=‘’ where  条件(字段名=‘ ’)

    7:查询数据

        select * from tableName   /*查询所有的数据*/

        select  * from   tableName where 条件  /* 条件查询所有字段 */

        select top 10 from tableName   /*  查询表中前10条数据 or  按条件查询前10条数据*/

        select top 10 from tableName  where 条件  /*  按条件查询前10条数据 */

       select distinct 字段名 from tableName ";//查询不重复的数据

    8、 删除数据

       delete from tableName where 条件   /* 删除行 */

       delete from tableName  /* 删除所有行 */

       drop tableName  /*删除表*/

    9、添加加字段:
       alter table tableName add 列名 varchar(20)10、删除字段

     alter table tableNamedrop column 字段名;
     
     
     
     
     
     
    可以参考:https://jingyan.baidu.com/article/c33e3f48d63800ea15cbb5cb.html   这个网站的增删改查很详细
  • 相关阅读:
    LA 6891 Money Transfers(最短路)
    Gym
    UVa 1662 Brackets Removal
    Gym 101334F Feel Good
    Gym 101334E Exploring Pyramids(dp+乘法原理)
    POJ 2112 Optimal Milking(二分+最大流)
    POJ 2115 C Looooops(模线性方程)
    UVa 11552 最小的块数(序列划分模型:状态设计)
    UVa 10534 波浪子序列(快速求LIS)
    UVa 10891 Sum游戏
  • 原文地址:https://www.cnblogs.com/my1227/p/11233013.html
Copyright © 2011-2022 走看看