sql basic Flashcards

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
Q

What is the WHERE clause in SQL?

A

The WHERE clause is used to filter records. It is case sensitive.

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

What does the % symbol do in a WHERE clause?

A

The % symbol is a wildcard character that represents zero, one, or multiple characters in a LIKE condition.

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

What is the LIKE operator in SQL?

A

used in a WHERE clause to search for a specified pattern in a column.

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

What does the error “UNIQUE constraint failed: Customers.customer_id” mean?

A

This error means that an attempt was made to insert a duplicate value into a column that has a UNIQUE constraint.

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

What is a FOREIGN KEY in SQL?

A

a field (or collection of fields) in one table that refers to the PRIMARY KEY in another table.

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

How do you update data in a table?

A

You can update data in a table using the UPDATE statement.

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

eg of update table ?

A

UPDATE table_name
SET column1 = value1, column2 = value2, …
WHERE condition;

32
Q

How do you delete data from a table?

A

You can delete data from a table using the DELETE statement.

33
Q

example of delete data

A

DELETE FROM table_name WHERE condition;

34
Q

can we have multiple condition in where clause?

A

yes we can use and , or

35
Q

AND

A

if we mention this then it must be true

36
Q

OR

A

If we are not sure then we can use this

37
Q

can we have and , or at same time

A

yes and (or)

38
Q

NOT

A

this gives opposite of required

39
Q

Not Types

A

NOT | <> | !=

40
Q

What is NULL in SQL?

A

NULL represents missing or unknown data in SQL. It is not the same as zero or an empty string.

41
Q

if we want null value

A

where column is null

42
Q

if we don’t want null values

A

where column is not null

43
Q

how can we write multiple condition like where and or or or or in same column

A

IN can be used

44
Q

if you want to search between the range

A

BETWEEN

45
Q

how can we arrage column in ascending or decending

A

ORDER BY column name or ORDER BY 1 (By default its acending) her 1 means true

46
Q

for ascending using order by

A

ORDER BY column name or ORDER BY column name ASC

47
Q

for decending using order by

A

ORDER BY column name DESC

48
Q

where we write order by

A

we must write at last of query

49
Q

if we don’t want duplicates to print

A

distinct

50
Q

if you want to print first 10

A

LIMIT 10 or Fetch first 10 rows only

51
Q

can we fetch last rows

A

NO we cant

52
Q

How Rename a column

A

AS

53
Q

TYPES of AS

A

column_name or “COLUMN Name”

54
Q

example of as

A

SELECT column_name AS new_column_name.

55
Q

how to make all column data caps

A

UPPER(Column Name)

56
Q

how to make all column data lower case

A

lower(Column Name)

57
Q

TO know the length of string (akil - 4)

A

LENGTH(Column name)

58
Q

Do length calculate the space

A

yes

59
Q

how to add string data in sql

A

Select ‘ what ever string u can write here ‘

60
Q

what is white space

A

the excess gap between string

61
Q

how do we eliminate white spaces

A

The TRIM() function removes leading and trailing spaces from a string.

62
Q

example of trim

A

Select TRIM ( ‘ what ever string u can write here ‘ ). &raquo_space; what ever string u can write here (no whitespaces)

63
Q

How do we add 2 columns

A

PIPES || ‘ ‘ || where ‘ ‘ will add spaces between (column1 || ‘ ‘ || column2)

64
Q

PIPes also called as

A

CONCAT

65
Q

to check condition true or false

A

BooLean ( ) - we specify column in the brackets

66
Q

Data checking in columns

A

Select column ,(‘data in column’ IN (column name, column name))

67
Q

Data checking using string

A

Select column ,(‘data in column’ IN (‘data in column ‘,’data in column ‘,’data in column ‘))

68
Q

Print of sub string by specifing star and end point

A

(SELECT SUBSTRING(‘Akhil is present’, Start point, End Point);)

69
Q

Print of sub string from start point only

A

(SELECT SUBSTRING(‘Akhil is present’ from 3 ); o/p - il is present

70
Q

to replace string

A

Replace (column , ‘existing data’ , ‘new data that replays’ )

71
Q

to know the position of the word or symbol

A

The POSITION() function returns the position of the first occurrence of a substring in a string.

72
Q

example of position

A

Eg abc@gmail.com then @ is at 4th position.

73
Q

if you don’t want to print the position specified

A

use +1

74
Q

Replace null with data

A

Coalesce ( column , ‘Data that you want to replace’ ):

75
Q

Single row function

A

4 rows input we get 4 rows output (allow duplicates)

76
Q

How do you check if a column contains a specific word in SQL?

A

You can use the LIKE operator with % wildcard characters. For example, WHERE column_name LIKE ‘%word%’.