Week 5 Flashcards
two components of applicaiton
how does sql link
what does it link to
grpahical interface and direct query
sql is used to pull info out of
DBMS
DDL
Data definiton language
commands that define a database, including creating, altering, and dropping tables/establish constraintsML
DML
data manipulation language
commands that mainitan and query a db
DCL
data control language
commands the contral db, administer priveleges and committ data
example of ddl
create tables
establish fk
drop or truncate tables
PHYSICAL DESIGN & MAINTENACNE
emaple of dml
load the database: insert data, update data, manipulate data with SELECT
implenentation & maintenance
DCL example
contrl database
GRANT ADD REVOKE
imp and maintenance
major create statements
CREATE schema- define portion of db owened by 1 user
CREATE table- define anew table and its columns
CREATE VIEW- defines logical table from one or more table or views
other create statments
create character, set, collation , translation..
CREATE TABLE Test1_T
(
Test1ID int PRIMARY KEY,
FirstName varchar(40) NOT NULL,
LastName varchar(30) NOT NULL,
State char(2) NULL
);
this is the formatting!!!
CREATE TABLE name(
(name) type PK (constraint),
(name) type (constraint),
)
HOW CAN WE ALTER TABLES
Change oclumn name, add a new column, drop/DELETE a column, change the columns like its null or not null
How to end off the diff rows in the the code?
just a comma!! after each
How to end off the different sectins of code? the cunkS?
;
How to alter a table to add?
ALTER TABLE name
ADD (name) type Not Null;
ALTER TABLE name
DROP COLUMN (name);
ALTER TABLE name
ALTER COLUMN (name) type Not Null;
How to alter a table to drop
ALTER TABLE name
DROP name;
How to alter table to alter column like the data type?
ALTER TABLE name
ALTER COLUMN __ varchar(#) Null;
5 types of constraints
NOT NULL
CHECK (like >= a value)
UNQIUE
PRIMARY KEY
FOREIGN KEY
how to add a constraint?
ALTER TABLE Test2_T
ADD CONSTRAINT FK_Test2_T_Test1_T FOREIGN KEY
(EMPLOYEEID)
REFERENCES Test1_T(TestID);
- ALTER TABLE ___name___
- ADD CONSTRAINT __name of constraint___ FOREIGN KEY
- Type the foreign key you wanna add
- REFERENCES Table(Column)
MAIN CODES
CREATE TABLE__
ALTER TABLE___
How to drop a component ?
ALTER TABLE __name__
DROP __Type___ _Name__;
COMPOENNENT TYPE: COLUMN, CONSTRAINT, INDEX
Insert statemetn
Adds one or more rows to a table or view
INSERT INTO table
(ColA, ColB, ColC) VALUES (1,2,3)
INSERT INTO __table__
Values (1,2,3)
UPDATE statment , no where clause
Changes existing data in atable or view
UPDATE name
SET Compinentype = ??
UPDATE table
SET ColC=6;
UDATE STATEMTN, WITH WEHRE CLAUSE!
UPDATE table name
SET ColC=10, ColB=20,
WHERE ColA= 2;
DELETE STATEMETN
removes one or more rows from a table!! not columns
DELET FROM name
WHERE columnA=3
How to change delete to verify rows to delete
SELECT!!! FIRST
SELECET*FROM table
WHERE colA=5
then delete
6 clauses of select statement
SELECT
FROM
WHERE
GROUPBY
HAVING
ORDER BY