Chapter 2 - SQL Flashcards

1
Q

What is SQL and what is it’s advantage?

A

Structured Query Language.
Previously Known as Structured English Query Language.

Advantage: simple and declarative so user don’t have to think much. Software can do operation optimisation

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

What syntax must u add after the SQL statement?

A

must add ;

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

How are comments done in SQL?

A

using –
or
using /* line 1 line 2 */

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

Naming convention for SQL

A

First character should be a letter
Uppercase and lowercase for different letters in one name
use underscore to connect different words
consistency: follow the same naming schemes for a whole project

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

Data types for SQL

A

Data types
* char(n). Fixed length character string, with user-specified length n.
* varchar(n). Variable length character strings, with user-specified maximum
length n.
* int. Integer (a finite subset of the integers that is machine-dependent).
* smallint. Small integer (a machine-dependent subset of the integer domain
type).
* numeric(p,d). Fixed point number, with user-specified precision of p digits, with
d digits to the right of decimal point. (ex., numeric(3,1), allows 44.5 to be stores
exactly, but not 444.5 or 0.32)
* real, double precision. Floating point and double-precision floating point
numbers, with machine-dependent precision.
* float(n). Floating point number, with user-specified precision of at least n digits.
* date, time, timestamp. For values contains date and time

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

How to perform SQL Select statement?

A

Select A1,A2
From R
where P

A is an attribute
R is a relation
P is a predicate

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

How to perform SQL Insert statement?

A

insert into R values(v1,v2,v3)
E.g. Insert into instructor values (‘10211’, ’Smith’, ’Biology’, 66000);

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

How to perform SQL delete?

A

Delete from R
e.g. delete from student

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

How to perform SQL create table?

A

CREATE TABLE TableName (
attribute1 type1 constraints1,
attribute2 type2 constraints2,
..
table-level constraints, …)

Create a new table in a database
CREATE TABLE Students (
sid serial,
name varchar(40),
dob date ,
gender char(1) CHECK (gender in (‘M’,’F’)),
degree integer
);
* check: checks whether an assertion is true, limit the value range
* Tables are removed via: DROP TABLE table_name

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

What is DDL and DML and what are their differences?

A

Data Definition Language: (CREATE, ALTER, DROP) TABLE

Data Manipulation Language: (SELECT, INSERT, UPDATE, DELETE)

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