美文网首页
数据库基础(一)

数据库基础(一)

作者: 秸秆混凝烧结工程师 | 来源:发表于2021-10-18 22:21 被阅读0次
  • Comments start with two hyphens. End each command with a semicolon.

-- SQL is not case-sensitive about keywords. The sample commands here
-- follow the convention of spelling them in upper-case because it makes
-- it easier to distinguish them from database, table, and column names.

-- Create and delete a database. Database and table names are case-sensitive.
CREATE DATABASE someDatabase;
DROP DATABASE someDatabase;

-- List available databases.
SHOW DATABASES;

-- Use a particular existing database.
USE employees;

-- Select all rows and columns from the current database's departments table.
-- Default activity is for the interpreter to scroll the results on your screen.
SELECT * FROM departments;

-- Retrieve all rows from the departments table,
-- but only the dept_no and dept_name columns.
-- Splitting up commands across lines is OK.
SELECT dept_no,
dept_name FROM departments;

-- Retrieve all departments columns, but just 5 rows.
SELECT * FROM departments LIMIT 5;

-- Retrieve dept_name column values from the departments
-- table where the dept_name value has the substring 'en'.
SELECT dept_name FROM departments WHERE dept_name LIKE '%en%';

-- Retrieve all columns from the departments table where the dept_name
-- column starts with an 'S' and has exactly 4 characters after it.
SELECT * FROM departments WHERE dept_name LIKE 'S____';

-- Select title values from the titles table but don't show duplicates.
SELECT DISTINCT title FROM titles;

-- Same as above, but sorted (case-sensitive) by the title values.
SELECT DISTINCT title FROM titles ORDER BY title;

-- Show the number of rows in the departments table.
SELECT COUNT(*) FROM departments;

-- Show the number of rows in the departments table that
-- have 'en' as a substring of the dept_name value.
SELECT COUNT(*) FROM departments WHERE dept_name LIKE '%en%';

-- A JOIN of information from multiple tables: the titles table shows
-- who had what job titles, by their employee numbers, from what
-- date to what date. Retrieve this information, but instead of the
-- employee number, use the employee number as a cross-reference to
-- the employees table to get each employee's first and last name
-- instead. (And only get 10 rows.)

SELECT employees.first_name, employees.last_name,
titles.title, titles.from_date, titles.to_date
FROM titles INNER JOIN employees ON
employees.emp_no = titles.emp_no LIMIT 10;

-- List all the tables in all the databases. Implementations typically provide
-- their own shortcut command to do this with the database currently in use.
SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE='BASE TABLE';

-- Create a table called tablename1, with the two columns shown, for
-- the database currently in use. Lots of other options are available
-- for how you specify the columns, such as their datatypes.
CREATE TABLE tablename1 (fname VARCHAR(20), lname VARCHAR(20));

-- Insert a row of data into the table tablename1. This assumes that the
-- table has been defined to accept these values as appropriate for it.
INSERT INTO tablename1 VALUES('Richard','Mutt');

-- In tablename1, change the fname value to 'John'
-- for all rows that have an lname value of 'Mutt'.
UPDATE tablename1 SET fname='John' WHERE lname='Mutt';

-- Delete rows from the tablename1 table
-- where the lname value begins with 'M'.
DELETE FROM tablename1 WHERE lname like 'M%';

-- Delete all rows from the tablename1 table, leaving the empty table.
DELETE FROM tablename1;

-- Remove the entire tablename1 table.
DROP TABLE tablename1;

相关文章

  • 2018-10-25day9数据库基础

    数据库基础 day9数据库基础

  • 数据库基础和SQL基础总结

    本文会总结下数据库知识,SQL基础,常用SQL语句总结; 一、数据库基础相关概念 二、数据库重点知识点 三、数据库...

  • 数据库基础Database1-初级SQL

    数据库基础Database1 一 基础概念 1. 概念 数据库管理系统(Database Management S...

  • 2019-08-01

    学习笔记 基础知识 第1章 基础知识 1.1 数据库基础 1.1.1 什么是数据库 数据库用于存储有组织的数据的容...

  • 数据库基础、FMDB

    数据库基础

  • 数据库优化学习笔记(二)

    数据库基础不是很牢固,补充下基础。 常见的数据库 阶层型数据库:用树型结构保存的数据库。 关系型数据库:见下图 主...

  • 2018-04-09 数据仓库技能要求

    一、基础技能1 关系数据库基础1.1. 关系数据库-mysql1.1.1 mysql 应用1.1.2 mysql ...

  • 数据库面试题

    数据库基础(面试常见题) 一、数据库基础 Oracle对象有哪些? 答案:表,表空间,用户,视图,索引,存储过程,...

  • OMIM 数据库详细介绍

    1 OMIM数据库基础介绍 1.1 基础介绍 OMIM数据库,OMIM 为“0nline Mendelian In...

  • Flask基础

    目录一、Flask基础二、数据库连接配置三、模板四、表单五、数据库 Flask框架 一、Flask基础 1.初始化...

网友评论

      本文标题:数据库基础(一)

      本文链接:https://www.haomeiwen.com/subject/tjkooltx.html