Cập nhật cơ sở dữ liệu khi cấu trúc thay đổi

Nhập môn Cơ sở dữ liệu quan hệ bằng SQL

Timo Grossenbacher

Data Journalist

Mô hình cơ sở dữ liệu hiện tại

Nhập môn Cơ sở dữ liệu quan hệ bằng SQL

Mô hình cơ sở dữ liệu hiện tại

Nhập môn Cơ sở dữ liệu quan hệ bằng SQL

Chỉ lưu dữ liệu DISTINCT trong các bảng mới

SELECT COUNT(*)
FROM university_professors;
 count
 -----
 1377
SELECT COUNT(DISTINCT organization) 
FROM university_professors;
 count
 -----
 1287
Nhập môn Cơ sở dữ liệu quan hệ bằng SQL

Chèn bản ghi DISTINCT vào các bảng mới

INSERT INTO organizations 
SELECT DISTINCT organization, 
    organization_sector
FROM university_professors;
Output: INSERT 0 1287
INSERT INTO organizations 
SELECT organization, 
    organization_sector
FROM university_professors;
Output: INSERT 0 1377
Nhập môn Cơ sở dữ liệu quan hệ bằng SQL

Câu lệnh INSERT INTO

INSERT INTO table_name (column_a, column_b)
VALUES ("value_a", "value_b");
Nhập môn Cơ sở dữ liệu quan hệ bằng SQL

ĐỔI TÊN cột trong affiliations

CREATE TABLE affiliations (
 firstname text,
 lastname text,
 university_shortname text,
 function text,
 organisation text
);
ALTER TABLE table_name
RENAME COLUMN old_name TO new_name;
Nhập môn Cơ sở dữ liệu quan hệ bằng SQL

XÓA cột trong affiliations

CREATE TABLE affiliations (
 firstname text,
 lastname text,
 university_shortname text,
 function text,
 organization text
);
ALTER TABLE table_name
DROP COLUMN column_name;
Nhập môn Cơ sở dữ liệu quan hệ bằng SQL
SELECT DISTINCT firstname, lastname, 
    university_shortname 
FROM university_professors
ORDER BY lastname;
-[ RECORD 1 ]--------+-------------
firstname            | Karl
lastname             | Aberer
university_shortname | EPF
-[ RECORD 2 ]--------+-------------
firstname            | Reza Shokrollah
lastname             | Abhari
university_shortname | ETH
-[ RECORD 3 ]--------+-------------
firstname            | Georges
lastname             | Abou Jaoudé
university_shortname | EPF
(truncated)

(551 records)
SELECT DISTINCT firstname, lastname 
FROM university_professors
ORDER BY lastname;
-[ RECORD 1 ]----------------------
firstname | Karl
lastname  | Aberer
-[ RECORD 2 ]----------------------
firstname | Reza Shokrollah
lastname  | Abhari
-[ RECORD 3 ]----------------------
firstname | Georges
lastname  | Abou Jaoudé
(truncated)

(551 records)
Nhập môn Cơ sở dữ liệu quan hệ bằng SQL

Giảng viên được nhận diện duy nhất bởi firstname, lastname

Nhập môn Cơ sở dữ liệu quan hệ bằng SQL

Bắt đầu làm nào!

Nhập môn Cơ sở dữ liệu quan hệ bằng SQL

Preparing Video For Download...