sql basic Flashcards
SQL
Structured Query Language. It’s a standard language for managing and manipulating databases.
creation of table in sql
create table ( ) ; – inside brackets we write data type with variable + primary constrain
eg of creation of table
CREATE TABLE department (
Department varchar(100),
Division varchar(100),
PRIMARY KEY (Department)
);
var char
that holds characters of variable length
can we metion more than specified data in var char eg var(50) . Can we give 50+
yes
eg of var char in creation of table
Department varchar(100), – column name (varchar – it can take data up to 100)
Constrain
Constrain is a data base ability to control what kind of data need to go into the given column. This is data type specific.
can we enter other data type after specified in the table
No
Primary key
A primary key is a column or a set of columns that uniquely identify each row in the table. It must contain unique values and cannot contain null values.
if we use primary key then we cant have duplicates
TRUE
will primary key allow null
no
How do you insert data into a table?
You can insert data into a table using the INSERT INTO
eg of insert
INSERT INTO department (Department, Division(Column) ) VALUES (‘Automotive’, ‘Auto & Hardware’(values in column));
how do we retrive all column from sql
SELECT *
FROM table_name;
What is * in select * from table name ?
selecting all columns
Retrival using column
SELECT column1, column2, …
FROM table_name;
can we have mutiple primary key in creation of table
no
statement in sql
();
eg of statement
creation , insertion, Retrival of data
can we mispell key words
no
comment in sql
– single line comment /**/ multiline comment
is ; manditory in selection statement
yes, but without that we can still continue
date in sql
data type, ‘YYYY-MM-DD’
row vs column
- |
What is the WHERE clause in SQL?
The WHERE clause is used to filter records. It is case sensitive.
What does the % symbol do in a WHERE clause?
The % symbol is a wildcard character that represents zero, one, or multiple characters in a LIKE condition.
What is the LIKE operator in SQL?
used in a WHERE clause to search for a specified pattern in a column.
What does the error “UNIQUE constraint failed: Customers.customer_id” mean?
This error means that an attempt was made to insert a duplicate value into a column that has a UNIQUE constraint.
What is a FOREIGN KEY in SQL?
a field (or collection of fields) in one table that refers to the PRIMARY KEY in another table.
How do you update data in a table?
You can update data in a table using the UPDATE statement.