- Primary key: A PRIMARY KEY constraint is one which uniquely identifies each record in a table and cannot contain NULL values (mySQL). A table can have only one primary key. On the other hand, unique can contain NULL value (even multiple).
Questions:
- Find second highest salary.
- Find employees those who have joined in last month.
- NOW()
- MONTH(column_name)
- How to write foreign key relation. (Inner/left join and start with child table)
- Difference between primary key and foreign key
- Composite key.
- Indexing
- sql freeze vs lock
Indexing
Indexing a column can speed up the searches (i.e. select * from where id=123). Indexing is helpful for searches but can hamper the speed during create, update, delete operations. Because,
1. For clustered index, column is reordered after inserting.
2. For non-clustered index, index value (like a new field of db) is needed to create.
During the search operation the Binary search operation is used instead of default Linear search operation. In binary search time get reduced.
Reference:
Unicode/UTF-8 data in mysql table
Set collation of table to utf8_unicode_ci
How to Count the String Occurrences in SQL
The following query will find the number of occurrences of 'is' in in Notes row of Employees table
Labels: SQL, Web development