SQL koder Flashcards

1
Q

Hvordan lager du en ny tabell?

A
CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
   ....);
CREATE TABLE kunde (
 Fornavn varchar(45),
 Etternavn varchar(45),
 PRIMARY KEY(KundeID)
 );
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Hvordan kan du legge inn informasjon i en database?

A

INSERT INTO table_name (column1, column2, …)
VALUES (value1, value2, …);

INSERT INTO reperasjoner (deler, starttid, slutttid, kostnad, …)
VALUES (skrue, 14:00, 17:00, 1000kr);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Hvordan oppdaterer man data?

A

UPDATE table_name
SET column1 = value1, column2 = value2, …
WHERE condition; (hvor skal dette endres?)

UPDATE reperasjoner
SET deler = svinghjul, starttid = 17:00
WHERE reperasjons-ID = 1;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Hvordan sletter man data?

A

DELETE FROM table_name WHERE condition;

DELETE FROM reperasjoner WHERE deler= ‘lakk’;

Da slettes hele raden som inneholdt lakk med tilhørende data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Hvordan kan man selektere ut data?

A

SELECT column1, column2, …
FROM table_name;

SELECT deler, starttid
FROM reperasjoner;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Hvordan kan man sortere data?

A

SELECT * FROM table_name
ORDER BY column1 DESC/ASC;

SELECT * FROM reperasjoner
ORDER BY starttid DESC;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Ascending

A

økende

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Descending

A

synkende

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Økende rekkefølge

A

Ascending

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Synkende rekkefølge

A

Descending

How well did you know this?
1
Not at all
2
3
4
5
Perfectly