SQL Structured Query Language
--hi world--
CREATE TABLE inimene(
nameID int Primary key identity(1,1),
eesimi varchar(25),
perenimi varchar(30),
synniaeg date,
pikkus decimal(6,2)
)
INSERT INTO inimene(eesimi, pikkus, synniaeg, perenimi)
VALUES ('Dave', 198.10, '2000-01-10', 'Fredd');
SELECT * FROM inimene
-- Tabwli muutimine, välja lisamine:
ALTER TABLE inimene ADD synnilinn varchar(20);
Select * from inimene
-- andmete uuedamine:
UPDATE inimene
SET synnilinn='Tallinn'
WHERE nameID=6 or nameID=7;
Select * from inimene;
--andmete kustutamine:
DELETE inimene
WHERE nameID=10 or nameID=8;
Select * from inimene
--hi world--
CREATE TABLE Product(
idProduct int Primary key identity(1,1),
Name varchar(20),
idCategory int,
Category_Name varchar(20),
Price decimal(4,2));
--hi world--
CREATE TABLE Category (
idCategory int Primary key identity(1,1),
idCategory varchar(25),
)
Restrictions:
- NOT NULL: The field must be filled in!
- UNIQUE: Non-repeating values in the field
- PRIMARY KEY: uniquely identifies a table row, assigning each row its own number (IDENTITY(1,1) or AUTO_INCREMENT – the primary key field is filled with automatically increasing numeric values).
- FOREIGN KEY: Defines a foreign key that defines a relationship between two tables (a relationship with the primary key of another table)
- CHECK: – Specifies a set of valid values.
--create table kursus(
--kursusID int primary key identity(1,1),
--kursusNimutus varchar(20),
--maht int,
--maksumus decimal(6,2),
--kirjeldus text);
insert into kursus(kursusNimutus, maht, maksumus)
values ('eesti keel', 200, 1000.2);
select * from kursus
--Create table amet(
--ametID int primary key identity(1,1),
--ametNimutus varchar(20) unique,
--kirjeldus text);
insert into amet(ametNimutus)
Values ('IT spetsialist');
insert into amet(ametNimutus)
Values ('IT tehnik');
insert into amet(ametNimutus)
Values ('IT admin');
select * from amet
create table tootaja(
tootajaID int primary key identity(1,1),
tootajaNimutus varchar(20),
perenimi varchar(20) not null,
synniage date,
aadress text,
telefon char(13),
amet int,
foreign key (amet) references amet(ametID))
Create table koolitus(
koolitusID int primary key identity(1,1),
kursus int,
foreign key (kursus) references kursus(kursusID),
tootaja int,
foreign key (tootaja) references tootaja(tootajaID),
koolitusAlgus date,
koolitusLopp date)