BIS II - SQL Flashcards
SQL
- Definition & use
Structured Query Language Standard relational database Used to - define and set up relations - ton insert, alter, and to delete data - to query data from one or more relations
Data Types
Tinyint
Binary variable (representing yes/no decisions)
int(m)
Integer numbers with an m maximum displayed places
float(m,d)
Float numbers with an m maximum displayed places and d decimal places
char(m)
Character string of length m
varchar(m)
character string of a variable length (m: maximum length)
date
Date in format YYYY-MM-DD
Creating a table
CREATE TABLE Customer ( Customer_id INT NOT NULL, Name VARCHAR(40) NOT NULL, PRIMARY KEY (Customer_id) )
Dropping a Table
DROP TABLE customer (can also be in lower case)
Adding new attributes
ALTER TABLE Customer
ADD rating INT NOT NULL AFTER
Discount`
Dropping attributes
ALTER TABLE Customer
DROP rating
Inserting new data records
INSERT INTO Customer
(Customer_id
, Name
, Address
) VALUES (NULL, James Bond
, Burgplatz 2`);
Altering data records
UPDATE Customer
SET Discount
= ‘0.08’ WHERE Customer
.Customer_id
= 1
Selecting an entire table
SELECT * FROM Customer
Selecting from a table
SELECT Name
, Address
FROM Customer