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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

常用基本SQL语句

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

? --常用Sql

  • 說明:創建數據庫?
    CREATE DATABASE database-name;
  • 說明:刪除數據庫?
    DROP DATABASE database-name;
  • 說明:創建新表?
    create table?depart?(dept_id?int(11) NOT NULL AUTO_INCREMENT,?
    dept_name?varchar(255) DEFAULT NULL, PRIMARY KEY (dept_id));?
    根據已有的表創建新表:?
    create table tab_new like tab_old (使用舊表B創建新表A)?
    備注:此種方式在將表B復制到A時候會將表B完整的字段結構和索引復制到表A中來?
    create table tab_new as select col1,col2… from tab_old definition only?
    備注:此種方式只會將表B的字段結構復制到表A中來,但不會復制表B中的索引到表A中來。這種方式比較靈活可以在復制原表表結構的同時指定要復制哪些字段,并且自身復制表也可以根據需要增加字段結構。?
    create table as select 會將原表中的數據完整復制一份,但表結構中的索引會丟失。?
    create table like 只會完整復制原表的建表語句,但不會復制數據。
  • 說明:刪除新表?
    drop table tabname;
  • 說明:增加一個列?
    alter table tabname add column column_name type
  • 說明:添加主鍵:?Alter table tabname add primary key(col)?
    說明:刪除主鍵:?Alter table tabname drop primary key?
    一個數據表只可以有一個主鍵,所以不存在刪除某一列的主鍵.
  • 說明:創建索引:create [unique] index idxname on tabname(col….)?
    刪除索引:drop index idxname?
    注:索引是不可更改的,想更改必須刪除重新建。
  • 說明:創建視圖: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:升序?
    總數: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:?
    一張表,一旦分組完成后,查詢后只能得到組相關的信息。?
    組相關的信息:(統計信息)?count,sum,max,min,avg 分組的標準)
  • 說明:between的用法,between限制查詢數據范圍時包括了邊界值,not between不包括?
    select * from table1 where time between time1 and time2?
    select a,b,c, from table1 where a not between 數值1 and 數值2
  • 說明:in 的使用方法?
    select * from table1 where a [not] in (‘值1’,’值2’,’值4’,’值6’)
  • ?

    轉載于:https://www.cnblogs.com/Auraro/p/7217928.html

    總結

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

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。