Unit 11 Flashcards
How to select something in SQL?
SELECT
FROM
WHERE
ORDER BY
How to create a table in SQL?
CREATE TABLE tblProduct
(
ProductID CHAR(4) NOT NULL PRIMARY KEY,
Description VARCHAR(20) NOT NULL,
Price CURRENCY
)
How to add a new column to a table in SQL?
ALTER TABLE tblProduct
ADD QtyInStock INTEGER
How to delete a column in SQL?
ALTER TABLE tblProduct
DROP QtyInStock
How to change the type/ length of a column?
ALTER TABLE tblProduct
MODIFY COLUMN Description VARCHAR (30) NOT NULL
How to define linked tables?
CREATE TABLE ProductComponent // creating table
( ProductID CHAR(4) NOT NULL,
CompID CHAR(6) NOT NULL,
Quantity INTEGER,
FOREIGN KEY ProductID REFERENCES Product(ProductID), //enforcing the relashonships
FOREIGN KEY CompID REFERENCES Component(CompID),
PRIMARY KEY (ProductID, CompID) )
How to insert data into a table?
INSERT INTO Product(ProductID, Description, Price) //note only put the ones you want to add data into
VALUES (“A345”, “Pink Rabbit”, 7.50)
How to update data in a table?
UPDATE Product
SET Description = “Blue Rabbit”, Price = 8.25
WHERE ProductID = “A345”
How to delete a record in SQL?
DELETE FROM Product
WHERE ProductID = “A345”
What is first normal form?
A data base will be in 1nf is it has no repearting attributes or grouped attributes
What is second normal form?
A database will be in 2nf if it is already in 1nf and is in a state where all of its non key attributes(columns) are dependant on/ related to the primary key.
What is 3rd normal form?
A database will be in 3nf it is alredy in 2nf and contains no attribbutes that (in addition to the primary key) ALSO depend on another attribute in the table.