Inserting, updating, and deleting data Flashcards
In column attributes what is the difference between VARCHAR and CHAR?
VARCHAR - variable chars * saves space
CHAR - will explicitly allocate specific number of characters like char(50).
PK describes what in column attributes?
The primary key uniquely identification on the table.
NN represents what in column attributes?
Determines if a column accepts null values, NOT NULL
Based on the column attribute pic what two columns on this customers table is optional?
the birth_date and phone columns are not marked NOT NULL, so they are optional values.
True or False
The primary key column is usually set to AI which is what?
Auto_Increment
When you don’t specify a value, MYSQL will provide a Default/Expression value of?
NULL
Write a query to insert the following information into the customers table.
Kelvin Waters
DOB: 08/02/1967
3401 Sunrise Villas Ct S, Tampa FL
Points 0 (default)
INSERT INTO customers (
first_name,
last_name,
birth_date,
address,
city,
state
)
VALUES (
‘Kelvin’,
‘Waters’,
‘1967-08-02’,
‘3401 Sunrise Villas CT S’,
‘Tampa’,
‘FL’
)
Write a query to insert multiple shippers in the shippers table
shipper1, shipper2, shipper3
INSERT INTO shippers (name)
VALUES
(‘shipper1’),
(‘shipper2’),
(‘shipper3’)
Exercise:
– Insert three rows into the products table
INSERT INTO products (
name,
quantity_in_stock,
unit_price
)
VALUES
(‘astroglide’, 10, 9.99),
(‘eatible panties’, 3, 14.89),
(‘dildo’, 16, 24.95)
What is this an example of?
INSERT INTO orders (customer_id, order_date, status)
VALUES (1, ‘2019-01-02’, 1);
INSERT INTO order_items
VALUES
(LAST_INSERT_ID(), 1, 1, 2.95),
(LAST_INSERT_ID(), 2, 1, 3.95)
Inserting hierarchical data on multiple tables (orders table has a parent child relationship with the order_items table)
How to copy one table data to another? (use the order table)
CREATE TABLE orders_archived AS
SELECT * FROM orders
When copying a table what two important attributes will NOT be copied?
The primary-key (pk) and auto increment (AI) status
What part of this query would be known as the subquery?
CREATE TABLE orders_archived AS
SELECT * FROM orders
SELECT * FROM orders
Truncating a table in mysql will do what exactly?
deletes all data in the table
This code is performing what in the orders_archived table that was previously truncated?
INSERT INTO orders_archived
SELECT *
FROM orders
WHERE order_date < ‘2019-01-01’
inserting filtered data via the WHERE statement into the orders_archived table.
What is the primary query of this query?
INSERT INTO orders_archived
SELECT *
FROM orders
WHERE order_date < ‘2019-01-01’
INSERT INTO orders_archived
What database is this query accessing?
USE sql_invoicing;
SELECT *
FROM invoices i
JOIN clients c
USING(client_id)
sql_invoicing
What column are these table being joined on?
USE sql_invoicing;
SELECT *
FROM invoices i
JOIN clients c
USING(client_id)
client_id on both tables