日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

常用基本SQL语句

發(fā)布時間:2023/12/10 数据库 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 常用基本SQL语句 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

? --常用Sql

  • 說明:創(chuàng)建數(shù)據(jù)庫?
    CREATE DATABASE database-name;
  • 說明:刪除數(shù)據(jù)庫?
    DROP DATABASE database-name;
  • 說明:創(chuàng)建新表?
    create table?depart?(dept_id?int(11) NOT NULL AUTO_INCREMENT,?
    dept_name?varchar(255) DEFAULT NULL, PRIMARY KEY (dept_id));?
    根據(jù)已有的表創(chuàng)建新表:?
    create table tab_new like tab_old (使用舊表B創(chuàng)建新表A)?
    備注:此種方式在將表B復(fù)制到A時候會將表B完整的字段結(jié)構(gòu)和索引復(fù)制到表A中來?
    create table tab_new as select col1,col2… from tab_old definition only?
    備注:此種方式只會將表B的字段結(jié)構(gòu)復(fù)制到表A中來,但不會復(fù)制表B中的索引到表A中來。這種方式比較靈活可以在復(fù)制原表表結(jié)構(gòu)的同時指定要復(fù)制哪些字段,并且自身復(fù)制表也可以根據(jù)需要增加字段結(jié)構(gòu)。?
    create table as select 會將原表中的數(shù)據(jù)完整復(fù)制一份,但表結(jié)構(gòu)中的索引會丟失。?
    create table like 只會完整復(fù)制原表的建表語句,但不會復(fù)制數(shù)據(jù)。
  • 說明:刪除新表?
    drop table tabname;
  • 說明:增加一個列?
    alter table tabname add column column_name type
  • 說明:添加主鍵:?Alter table tabname add primary key(col)?
    說明:刪除主鍵:?Alter table tabname drop primary key?
    一個數(shù)據(jù)表只可以有一個主鍵,所以不存在刪除某一列的主鍵.
  • 說明:創(chuàng)建索引:create [unique] index idxname on tabname(col….)?
    刪除索引:drop index idxname?
    注:索引是不可更改的,想更改必須刪除重新建。
  • 說明:創(chuàng)建視圖:create view viewname as select statement?
    刪除視圖:drop view viewname
  • 說明:幾個簡單的基本的sql語句?
    選擇:select * from table1 where 范圍?
    插入:insert into table1(field1,field2) values(value1,value2)?
    刪除:delete from table1 where 范圍?
    更新:update table1 set field1=value1 where 范圍?
    查找:select * from table1 where field1 like ’%value1%’ —like的語法很精妙,查資料!?
    排序:select * from table1 order by field1,field2 [desc]?
    desc:降序,asc:升序?
    總數(shù):select count as totalcount from table1?
    求和:select sum(field1) as sumvalue from table1?
    平均:select avg(field1) as avgvalue from table1?
    最大:select max(field1) as maxvalue from table1?
    最小:select min(field1) as minvalue from table1
  • 分組:Group by:?
    一張表,一旦分組完成后,查詢后只能得到組相關(guān)的信息。?
    組相關(guān)的信息:(統(tǒng)計信息)?count,sum,max,min,avg 分組的標(biāo)準(zhǔn))
  • 說明:between的用法,between限制查詢數(shù)據(jù)范圍時包括了邊界值,not between不包括?
    select * from table1 where time between time1 and time2?
    select a,b,c, from table1 where a not between 數(shù)值1 and 數(shù)值2
  • 說明:in 的使用方法?
    select * from table1 where a [not] in (‘值1’,’值2’,’值4’,’值6’)
  • ?

    轉(zhuǎn)載于:https://www.cnblogs.com/Auraro/p/7217928.html

    總結(jié)

    以上是生活随笔為你收集整理的常用基本SQL语句的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。