Sql and Databases Flashcards

1
Q

Select Statement in sql.

A

SELECT * from Tablename;

Select collumname,collumname2 from table name;

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

How to select distinct values

A

Select Distinct collumname from tablename;

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

what goes around a string when being matched

A

single quotes.

‘example’

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

How to specify Selection order?

A

Select * From Tablename orderby collumname asc/desc;

(can have multiple ordering if a comma seperates them)

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

Insertion of sql 2 methods

A
  • Insert into tablename values(value1,value2,…..); (note: must have all table values)
  • Insert Into tablename (collum1,collum2,…) values(value1,value2,…);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Updating a table

A

UPDATE tablename

SET column1=value1, collumn2=value2,….

where some-collumn=somevalue;

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

Deleting

A

Delete from tablename where somecolumn=somevalue;

(deletes a row)

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

What does the wildcard % mean

A

substtues for 0 or more characters.

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

what does the wildcard _ mean

A

substitutes for 1 character

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

what does the wildcard [] , and [^ } mean

A

sets range of character to match, or to not match (with ^)

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

Inner join

A

Returns the rows mentioned from multiple tables wher ethe condition is met.

Select collumnnames from table1 innerjoin table2 on t1.name=t2.name;

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

usuing a where instead of a innerjoin

A

Select collumnames from tablenames where table1.ID=table2.ID;

note all table names are listed

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

what is a union and unionall?

A

Union combines 2 or more select statements (only gets distrink values)

Unionall- the same but shows non distink values.

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

Select into

A

Copies data from one table into a new table.

Select collumnnames into newtable from table1;

(note if where 1=0 is used a new table of the same form is created with no data)

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

INsert into

A

Copies data from one table into an exisitng table.

Insert into table2 (collumname) select columnnames from table1;

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

Create table

A

Create table tablename

columnname datatype(size) consttraints ;

Constanits eg not null,unique,primary key, forign key, default, check

17
Q

The constaints when creating a table?

A
  • Not Null
  • Unique
  • Primary key
  • forieign key
  • default
  • auto increment
  • check
18
Q

Alternative way to add a primary key (and composite key) when creating a table.

A

Primary key(columnname,column2name)

19
Q

what datatype is a string?

A

varchar

20
Q

how to create a forign key?

A

columnname datatype Forign key references tablename(columnname)

21
Q

Alter table

A
  • Alter table tablename add/alter columnname datatype
  • Alter table tablename drop column columnname

Can be used to alter a contraint with alter constaintname(column)

22
Q

2 stages of normailsation

A
  1. All data values are atomic - no repeating groups
  2. Contains no partial key dependancies
  3. contains no non-key dependancies