3 MySQL SQL基礎

來源:互聯網
上載者:User

標籤:des   style   blog   http   io   ar   color   sp   strong   

目錄

1. SQL概述
2. 資料庫操作
3. 表操作
4. 記錄操作

1. SQL概述

  SQL,結構化查詢語言 (SQL)(Structured Query Language),一種資料庫查詢和程式設計語言,用於存取資料以及查詢、更新和管理關聯性資料庫系統。不區分大小寫。

  主要包含6個部分:
  1. 資料定義語言 (Data Definition Language)(DDL):常見保留字CREATE和DROP。
  2. 資料查詢語言(DQL):SELECT, ORDER BY。
  3. 資料操作語言(DML):INSERT,UPDATE和DELETE。
  4. 資料控制語言(DCL):GRANT,REVOKE。
  5. 交易處理語言(TPL):BEGIN TRANSACTION,COMMIT和ROLLBACK。
  6. 指標控制語言(CCL):DECLARE CURSOR,FETCH INTO。

SQL主要操作:增、刪、改、查。
SQL主要操作對象:資料庫、表、記錄。
(注意:以下實驗操作只拿來入門練手,SQL遠比這些強大!)

2. 資料庫操作

  2.1 建立資料庫。通過phpMyAdmin進入MySQL,點擊左欄中的SQL按鈕,如。

     

  在彈出框中輸入:create database schoolDB; 點擊執行。

        

  2.2 查詢資料庫
  show databases;

  
  2.3 刪除資料庫
  drop database schoolDB;

  

  show databases;

  


3. 表操作
  3.1 建立表
  create database schoolDB;
  在左側邊欄中選中schooldb;在右邊導覽列中點擊SQL按鈕,如。下文在資料庫中的操作都可以通過該按鈕開啟SQL編輯框。

  
  create table student (
  id int(5) not null,
  name varchar(20),
  birthday date
  );

   

  3.2 查詢表
  show tables;
  desc student;

   

  3.3 更改表
  增加列 alter table student add column phone char(11);
  刪除列 alter table student drop column phone;
  
  3.4 刪除表
  drop table student;

4. 記錄操作
  4.1 建立表
  create table student (
  id int(5) not null,
  name varchar(20),
  birthday date
  );
  插入記錄
  insert into student values(1, ‘guo jing‘, ‘1990-01-01‘);
  insert into student values(2, ‘huang rong‘, ‘1992-02-02‘);
  insert into student values(3, ‘ling hu‘, ‘1993-03-03‘);
  insert into student values(4, ‘dong fang‘, ‘1994-04-04‘);

  4.2 查詢記錄
  select * from student;

  

  4.3 更改記錄
  update student set birthday=‘1993-04-04‘ where name=‘dong fang‘;

  4.4 刪除記錄
  delete from student where name=‘dong fang‘;

3 MySQL SQL基礎

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.