SQL-basic

SQL, ‘Structured Query Language’, is a programming language designed to manage data stored in relational databases.

  • Relational Databases:
    • a database that organizes information into one or more tables. A table is a collection of data organized into rows and columns. Tables are sometimes referred to as relations.
    • All data stored in a relational database is of a certain data type. Some of the most common data types are:
      1. Integer, a positive or negative whole number
      2. Text, a text string
      3. Date, the date formatted as YYYY-MM-DD for the year, month, and day
      4. Real, a decimal value
  • SQL statement:

    • Statements always end in a semi-colon ;
    • Clauses perform specific tasks in SQL. By convention, clauses are written in capital letters. Clauses can also be referred to as commands. CREATE TABLE (below) is a clause.
    • (column_1 data_type, column_2 data_type, column_3 data_type) is a parameter. A parameter is a list of columns, data types, or values that are passed to a clause as an argument. Here, the parameter is a list of column names and the associated data type.
    • example:

      CREATE TABLE table_name (
      column_1 data_type, 
      column_2 data_type, 
      column_3 data_type
      );
    • Insert: INSERT INTO celebs (id, name, age) VALUES (1, 'Justin Bieber', 21);

    • Select: SELECT name FROM celebs; SELECT DISTINCT is used to return unique values in the result set. It filters out all duplicate values.
    • Update:
      UPDATE celebs
      SET age = 22
      WHERE id = 1;
    • Alter added a new column to the table: ALTER TABLE celebs ADD COLUMN twitter_handle TEXT;
    • Delete: DELETE FROM celebs WHERE twitter_handle IS NULL;
    • LIKE is a special operator used with the WHERE clause to search for a specific pattern in a column. The _ means you can substitute any individual character here without breaking the pattern.

      SELECT * FROM movies
      WHERE name LIKE 'Se_en';
    • % is a wildcard character that matches zero or more missing letters in the pattern.

    • A% matches all movies with names that begin with “A”
    • %a matches all movies that end with “a”
    • Order By: sort the result set by a particular column either alphabetically or numerically. ASC or DESC
    • Limit: specify the maximum number of rows the result set will have.
SELECT * FROM movies
ORDER BY imdb_rating DESC;
  • Aggregate Functions: compute a single result from a set of input values.

    • Count: takes the name of a column as an argument and counts the number of rows where the column is not NULL SELECT COUNT(*) FROM fake_apps;
    • Group By: only used with aggregate functions. It is used in collaboration with the SELECT statement to arrange identical data into groups. Here, our aggregate function is COUNT() and we are passing price as an argument to GROUP BY. SQL will count the total number of apps for each price in the table. SELECT price, COUNT(*) FROM fake_apps
      GROUP BY price;
    • Sum: SELECT SUM(downloads) FROM fake_apps;
    • MAX(): takes the name of a column as an argument and returns the largest value in that column. SELECT MAX(downloads) FROM fake_apps;
    • MIN(): takes the name of a column as an argument and returns the smallest value in that column.
    • AVG() function works by taking a column name as an argument and returns the average value for that column. SELECT AVG(downloads) FROM fake_apps;
    • ROUND(): takes a column name and an integer as an argument. It rounds the values in the column to the number of decimal places specified by the integer.
  • MULTIPLE TABLES:

    • primary key: serves as a unique identifier for each row or record in a given table. The primary key is literally an id value for a record.
    • Foreign Key: a column that contains the primary key of another table in the database. We use foreign keys and primary keys to connect rows in two different tables. One table’s foreign key holds the value of another table’s primary key. Unlike primary keys, foreign keys do not need to be unique and can be NULL.
    • cross join: SELECT albums.name, albums.year, artists.name FROM albums, artists
    • Inner Join:
      SELECT
      *
      FROM
      albums
      JOIN artists ON
      albums.artist_id = artists.id;
    • Left Outer Join: Outer joins also combine rows from two or more tables, but unlike inner joins, they do not require the join condition to be met. Instead, every row in the left table is returned in the result set, and if the join condition is not met, then NULL values are used to fill in the columns from the right table.
      SELECT
      *
      FROM
      albums
      LEFT JOIN artists ON
      albums.artist_id = artists.id;
    • Aliases: AS is a keyword in SQL that allows you to rename a column or table using an alias.
instantclient-basic-w是Oracle提供的一个软件包,用于在Windows操作系统上运行Oracle数据库客户端应用程序。它是Oracle Instant Client系列中的一个成员,旨在简化和加速Oracle数据库的部署和连接过程。 instantclient-basic-w包含了Oracle客户端应用程序所需的基本组件,包括:OCI(Oracle Call Interface)库、SQL*Plus命令行工具、创建Oracle数据库连接的必要配置文件以及一些辅助工具等。使用这个软件包可以方便地在Windows系统上进行Oracle数据库的连接、数据查询、事务处理等各种数据库操作。 与其他Oracle数据库客户端软件相比,instantclient-basic-w具有以下几个优点: 1. 简化部署:使用这个软件包可以避免繁琐的安装过程,只需要解压缩即可安装使用。无需安装整个Oracle数据库软件,减少了部署和维护的成本和工作量。 2. 轻量级:instantclient-basic-w只包含了必要的组件,不占用过多的系统资源,适合在较低配置的Windows计算机上运行。 3. 高性能:OCI库是Oracle数据库的核心部分,通过使用这个库,可以获得较高的数据库访问性能和效率。 4. 兼容性好:instantclient-basic-w与其他Oracle数据库客户端软件兼容性良好,可以与Oracle数据库的不同版本进行连接和通信。 5. 简单易用:SQL*Plus命令行工具提供了一个交互式的界面,使用户可以方便地输入和执行SQL语句,对数据库进行管理和查询。 总之,instantclient-basic-w是一个方便、高效、易用的Oracle数据库客户端软件包,为在Windows系统上进行Oracle数据库操作提供了便利和支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值