Se_QL Flashcards
create
CREATETABLEExperiment(
experimentIdINTNOTNULL,
PRIMARYKEY(experimentId)
);
insert
INSERTINTOExperiment(experimentId,name
VALUES(2,’Xbox’),
(3,’SharepointQuery’);
delete
drop table “tablename”
alter: add a column
ALTERTABLEExperiment
ADDpreConfiguredReportvarchar(10);
update
update tablename set colname = somevale where colname == condition
drop rows
drop
update multiple conditions
‘UPDATE Experiment set experimentStatus = ‘Error’, jobMessage = ‘{}’ where experimentId = {}’’‘.format(error, experiment_id))
insert single value
INSERT INTO table_name (col1)
VALUES (value1);
note: other rows entries become null which later can be added using “update”
rename column name in SQL server
EXEC sp_rename ‘tablename.columnanme’, ‘newcolumn_name’, ‘COLUMN’;
rename column in my sql
ALTER TABLE table_name
CHANGE COLUMN old_name TO new_name;
rename tablename in microsoft sql server
EXEC sp_rename ‘TableOldName’, ‘TableNewName
get table information schema
select *
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME=’tableName’
get table column information schema
select *
from INFORMATION_SCHEMA=
where TABLE_NAME=’tableName’
delete rows on condition
DELETE FROM Customers WHERE CustomerName=’Alfreds Futterkiste’;
delete all records
DELETE FROM table_name;
select min or max of a column
select min/max(column name)
where tablename
note: use it as part of a where condition
set primary key
primary key can only be unique
create table(col1 int,col2 varchae, primary ket(col1))
insert with where condition ?
Insert does not accept where conditions
sql operations; row-wise ? or column-wise?
row-wise
where negate condition
where “column name” IS NOT Null
where “column name” NOT like “result”
where “col name” < 3000 or “col name” > 5000
Note: other complex conditions needs to be added
delete table
drop tablename
delete columns
ALTER TABLE tablname DROP COLUMN col1, col2
make certain columns to index
CREATE INDEX indexname ON tablename (col1,col2....)
- this sorts the column values making it easier while fetching information
- runtime was reduced considerably from 14 to 2 mins
drop indexname
DROP INDEX index_name on table_name
SQL
structured query language
Data models
Data models define how data is connected to each other and how they are processed and stored inside the system
ER models
Entity–relationship model
An entity–relationship model describes interrelated things of interest in a specific domain of knowledge. A basic ER model is composed of entity types and specifies relationships that can exist between entities
NoSQL
can retrieve unstructured data
Entity
person, place thing or event, unique and distinct
Attribute
characteristic of an entity
Relationship and relationship types
describes association among entities
one to many
many to many
one to one
Relationship
describes association among entities
- one to many: one customer to invoices
- many to many: students to classes
- one to one: manager to store
ER diagrams
shows relationship
business process
visual representation
show links (primary keys)
primary key
column with unique id of every row
foreign key
one or more column can be used to identify a row
types of ER diagrams
We have the Chen notation, and there’s the Crow’s foot notation, and then there’s the UML class diagram notation.