zoukankan      html  css  js  c++  java
  • 转: sqlserver常用sql语句,更改字段,建立唯一键,多个字段去重复等

    [sql] view plain copy print?在CODE上查看代码片派生到我的代码片
    --修改字段类型:  
    --alter table 表名 alter column 待修改字段名 待修改字段类型  
    alter table users alter column userid varchar(10)  
      
    --多个字段建立唯一索引  
    create unique index [索引名] on 表名(字段名,字段名)  
    alter table 表名 add constraint 约束名 unique (字段名)  
    alter table 表名 add constraint 约束名 unique (字段名,字段名)  
      
    --创建表的时候创建自增主键  
    create table tb(id int identity(1,1) primary key )   
      
    --修改字段主键  自增进入ssms界面设置  
    alter table tb alter column id int not null   
    alter table tb add constraint pkid primary key (id)  
      
    --修改字段为非空  
    alter table tb alter column id int not null   
      
    --建立索引  
    create index mycolumn_index on mytable (myclumn)   
    [sql] view plain copy print?在CODE上查看代码片派生到我的代码片
    --AmazonOrderId和seller_id两个字段重复  
    SELECT count(*)   
    FROM (  
             SELECT rn = ROW_NUMBER()OVER(PARTITION BY AmazonOrderId, seller_id ORDER BY GETDATE()), *   
             FROM Orders  
         ) t  
    WHERE rn = 1  

    原文: http://blog.csdn.net/smartsmile2012/article/details/44100955

  • 相关阅读:
    POJ
    服务器端控件的属性
    生成验证码的代码
    无法检测到的代码原因
    Jquery获取服务器端控件的三种方式
    hdu-2421 Deciphering Password 数学姿势
    KM算法 带权二分匹配 O(n^3)
    hdu-3966 Aragorn's Story 树链剖分
    头文件
    输入外挂
  • 原文地址:https://www.cnblogs.com/liuwj/p/5282465.html
Copyright © 2011-2022 走看看