zoukankan      html  css  js  c++  java
  • sql查询语句

    突然觉得查询语句蛮难的,不知道怎么查询。

    判断一个两个条件算是还可以,多个条件判断有点想不出,查了点东西,留着看看。

    查询数据库中含有同一这字段的表:
    select name from sysobjects where xtype = 'u' and id in(select id from syscolumns where name = 's3')
    根据出生日期可以算出年龄:
    select datediff(year,scrq,'2013') as 年龄 from page_shsjgrgl
    根据当前年份自动算出年龄
    select datediff(year,csny,cast(YEAR(GETDATE()) as char))
    select year(djsj) from page_shsjgrgl
    select month(djsj) from page_shsjgrgl
    select day(djsj) from page_shsjgrgl
    在同一数据库中复制表结构:
    select * into a from b where 1<>1
    当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'aa' 中的标识列插入显式值。
    set identity_insert aa ON----设置打开,
    批量插入:
    insert into aa(Customer_ID, ID_Type, ID_Number) select Customer_ID, ID_Type, ID_Number from TCustomer;
    set identity_insert aa OFF---关闭
    不同数据库之间的复制:
    复制结构:
    select * into test.dbo.b from GCRT.dbo.page_shsjgrgl where 1<>1
    复制内容:
    insert into test.dbo.b(xm,ssdq) select xm,ssdq from GCRT.dbo.page_shsjgrgl
    查看数据库中所有的数据表表名:
    select name from SysObjects where type='u'
    查看数据库中所有表含有同一字段的表:
    select name from sysobjects where xtype = 'u' and id in(select id from syscolumns where name = '同一字段')
    查看数据表中的所有字段:
    select name from Syscolumns where id=object_id('表名')
    查询数据库时随机10条记录:
    select top 10 * from td_areacode order by newid()
    修改字段类型:
    ALTER TABLE 表名 ALTER COLUMN 字段名 varchar(30) NOT NULL
    use ZHJIANGJGYL
    declare @temp nvarchar(30)
    set @temp = 'ZWI4'
    select hllx from page_yljg_zyry where hllx not in(
    select
    case @temp when ''
    then ''
    else b1 end
    from (
    select * from TD_Code where page_en='page_yljg_zyry' and B2='ZWI'
    ) s where s.b1 !=
    case @temp when '' then '' else @temp end
    )
    更改数据库表字段类型:
    alter table page_shsjgrgl alter column s1 int
  • 相关阅读:
    <h1><h6>,<head>,<header>,<hr>,<html>标签文档
    <datalist>,<dl>,<dt>,<dd>,<del>,<details>,<div>,<dfn>标签文档
    <fieldset>,<figcaption>, <figure>,<footer>,<form>标签文档
    <b>,<base>,<bdo>,<blockquote>,<body>,<br>,<button>标签文档
    css footer自适应布局
    scss 常用mixins
    <em>,<embed>标签文档
    <canvas>,<caption>,<cite>, <code>,<col>, <colgroup>标签文档
    <a>,<abbr>,<address>,<area>,<article>, <aside>, <audio>标签文档
    SAP:常用的Tcode
  • 原文地址:https://www.cnblogs.com/linb/p/2892238.html
Copyright © 2011-2022 走看看