SQL-Intro

Agenda

  1. What is a database?
  2. CREATE TABLE
  3. Column Constraints
  4. INSERT 
  5. UPDATE 
  6. DELETE

What is a database?

База даних

Системи керування баз даних

Програма 1

Програма 1

Програма 1

NOT NULL
UNIQUE
PRIMARY KEY
FOREIGN KEY
CHECK
DEFAULT

Column Constraints

Foreign key

create table car (
	id INT PRIMARY KEY,
	engine FLOAT,
	color VARCHAR(255),
	purchased TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Create database

Task

Create a table with name property and with columns such as id, name, size, created_at.

Id should be INT and PRIMARY KEY auto_increment .

Name should be VARCHAR NOT NULL.

Size should be FLOAT.

Created_at should be TIMESTAMP DEFAULT CURRENT_TIMESTAMP. 

create table property(
	id int primary key auto_increment,
	name varchar(255) NOT NULL,
	size float,
	created_at timestamp DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO property(id, name, size, created_at) 
VALUES (NULL, 'Хата', 25, '2019-11-16 15:11:03');

Insert

Task

Insert into table property values:

552, 'The best house', 1001, '2016-11-16 15:11:03'

UPDATE property 
SET name = 'New name';

Update

Task

Update table property and set the size as NULL.

DROP table property;

Delete

Discussion