SQL Concepts-2
As we saw in previous blog, we are continuing the same i.e understanding concepts of SQL.
Q. How can we create a composite key?
- The combination of two or more columns that are used for unique identification of row in table.
- Sometimes more than one attribute is needed to identify an entity.
- In simple words we can say that, primary key created on multiple columns.
Q. What is data integrity?
- The consistency and accuracy of data is called as data integrity.
- Data integrity is classified into two types :
- System defined integrity : (using constraints)
- User defined integrity : (using triggers)
Again the system integrity is divided into three types:
1) Entity Integrity :
Entity integrity is used for uniquely identifying entity of each row in table. We can apply this to table by specifying primary key, unique key and not null.
2) Referential Integrity :
Referential integrity is used for creating relationship between tables. We can apply this using foreign key.
3) Domain Integrity :
Domain integrity is used for defining rules for values, range and format which is followed by data values in the database. We can apply this using check and default constraints.
- Example : Below figure shows data integrity i.e in my parent table i have two Id but when i insert Id=3 in child table for CustomerId_fk it shows this error :
Q. How to write a simple SQL with WHERE clause?
- The WHERE clause filters the records and returns only necessary(required) data.
- If the given condition satisfied, then only it returns a specific value from table.
- Example :
Q. What is an ALIAS in SQL?
Q. Explain the inner vs left vs right join?
Inner Join :
- The inner join keyword returns matching records from both tables.
- Example :
Left Join :
- The left join keyword returns all records from left table and matching records from right table.
- Example :
- The right join keyword returns all records from right table and matching records from left table.
- Example :
Thank You!!!
For more understanding watch below video :
Comments
Post a Comment