sql basic Flashcards

(76 cards)

1
Q

SQL

A

Structured Query Language. It’s a standard language for managing and manipulating databases.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

creation of table in sql

A

create table ( ) ; – inside brackets we write data type with variable + primary constrain

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

eg of creation of table

A

CREATE TABLE department (
Department varchar(100),
Division varchar(100),
PRIMARY KEY (Department)
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

var char

A

that holds characters of variable length

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

can we metion more than specified data in var char eg var(50) . Can we give 50+

A

yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

eg of var char in creation of table

A

Department varchar(100), – column name (varchar – it can take data up to 100)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Constrain

A

Constrain is a data base ability to control what kind of data need to go into the given column. This is data type specific.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

can we enter other data type after specified in the table

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Primary key

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

if we use primary key then we cant have duplicates

A

TRUE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

will primary key allow null

A

no

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you insert data into a table?

A

You can insert data into a table using the INSERT INTO

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

eg of insert

A

INSERT INTO department (Department, Division(Column) ) VALUES (‘Automotive’, ‘Auto & Hardware’(values in column));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

how do we retrive all column from sql

A

SELECT *
FROM table_name;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is * in select * from table name ?

A

selecting all columns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Retrival using column

A

SELECT column1, column2, …
FROM table_name;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

can we have mutiple primary key in creation of table

A

no

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

statement in sql

A

();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

eg of statement

A

creation , insertion, Retrival of data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

can we mispell key words

A

no

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

comment in sql

A

– single line comment /**/ multiline comment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

is ; manditory in selection statement

A

yes, but without that we can still continue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

date in sql

A

data type, ‘YYYY-MM-DD’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

row vs column

A
  • |
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the WHERE clause in SQL?
The WHERE clause is used to filter records. It is case sensitive.
26
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.
27
What is the LIKE operator in SQL?
used in a WHERE clause to search for a specified pattern in a column.
28
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.
29
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.
30
How do you update data in a table?
You can update data in a table using the UPDATE statement.
31
eg of update table ?
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
32
How do you delete data from a table?
You can delete data from a table using the DELETE statement.
33
example of delete data
DELETE FROM table_name WHERE condition;
34
can we have multiple condition in where clause?
yes we can use and , or
35
AND
if we mention this then it must be true
36
OR
If we are not sure then we can use this
37
can we have and , or at same time
yes and (or)
38
NOT
this gives opposite of required
39
Not Types
NOT | <> | !=
40
What is NULL in SQL?
NULL represents missing or unknown data in SQL. It is not the same as zero or an empty string.
41
if we want null value
where column is null
42
if we don’t want null values
where column is not null
43
how can we write multiple condition like where and or or or or in same column
IN can be used
44
if you want to search between the range
BETWEEN
45
how can we arrage column in ascending or decending
ORDER BY column name or ORDER BY 1 (By default its acending) her 1 means true
46
for ascending using order by
ORDER BY column name or ORDER BY column name ASC
47
for decending using order by
ORDER BY column name DESC
48
where we write order by
we must write at last of query
49
if we don’t want duplicates to print
distinct
50
if you want to print first 10
LIMIT 10 or Fetch first 10 rows only
51
can we fetch last rows
NO we cant
52
How Rename a column
AS
53
TYPES of AS
column_name or "COLUMN Name"
54
example of as
SELECT column_name AS new_column_name.
55
how to make all column data caps
UPPER(Column Name)
56
how to make all column data lower case
lower(Column Name)
57
TO know the length of string (akil - 4)
LENGTH(Column name)
58
Do length calculate the space
yes
59
how to add string data in sql
Select ' what ever string u can write here '
60
what is white space
the excess gap between string
61
how do we eliminate white spaces
The TRIM() function removes leading and trailing spaces from a string.
62
example of trim
Select TRIM ( ' what ever string u can write here ' ). >> what ever string u can write here (no whitespaces)
63
How do we add 2 columns
PIPES || ' ' || where ' ' will add spaces between (column1 || ' ' || column2)
64
PIPes also called as
CONCAT
65
to check condition true or false
BooLean ( ) - we specify column in the brackets
66
Data checking in columns
Select column ,(‘data in column’ IN (column name, column name))
67
Data checking using string
Select column ,(‘data in column’ IN ('data in column ','data in column ','data in column '))
68
Print of sub string by specifing star and end point
(SELECT SUBSTRING('Akhil is present', Start point, End Point);)
69
Print of sub string from start point only
(SELECT SUBSTRING('Akhil is present' from 3 ); o/p - il is present
70
to replace string
Replace (column , ‘existing data’ , ‘new data that replays’ )
71
to know the position of the word or symbol
The POSITION() function returns the position of the first occurrence of a substring in a string.
72
example of position
Eg abc@gmail.com then @ is at 4th position.
73
if you don’t want to print the position specified
use +1
74
Replace null with data
Coalesce ( column , 'Data that you want to replace' ):
75
Single row function
4 rows input we get 4 rows output (allow duplicates)
76
How do you check if a column contains a specific word in SQL?
You can use the LIKE operator with % wildcard characters. For example, WHERE column_name LIKE '%word%'.