SQL SERVER PART I

 Hey Guys, I hope that you are enjoying with my blogs writing and today's we will cover some  "SQL SERVER" Concepts.


Microsoft SQL Server is a relational database management system, or RDBMS, developed and marketed by Microsoft.
As a database server, it is a software products with primary function of storing and retrieving data as requested by other software application.
Initial Releases is April 24, 1989;

    Q. Explain what is a Identity column ?
  • Identity Column means its increase the indexing automatically in SQL.
  • For Example: Below has given a table which Id has autoincrement.
    To Implement this Settings go to Column properties -> Indentity Specification->Double click on that->Double click on Is Identity 
  1. Q. Are Nulls allowed in Foreign Keys ?
  • Yes, it can be null or duplicate. foreign key containing null values cannot match the values of a parent key. However, a null foreign key value is always valid, regardless of the value of any of its non-null parts.
  • For Example
    Above has mentioned if we will give null value to foreign key then it will be ok.
     Q. How can we create composite key ?
  • In Database design, a composite key is a candidate key that consist of two or more attributes ( table columns) that together uniquely identify an entity occurrence(table row).
  •  For Example: I have created a table name" tblCustomer2".
  • In that we have taken more than two Primary key which is also known as Composite key.   
    We have taken Id and FirstName as a Primary key.
     Q. How to write a simple SQL with "Where" clause ?
  •  The Where  clause is used to filter records.
  • Its filter those records which fulfil conditions.
  • Syntax:  
          select Column1, Column2..,
          from table_name
          where condition;
  •  Example: select * from tblCustomer1
    This will show whole records of tblCustomer1. 


  • But in case of  Where Clause it gives particular record.

        Note: Its not only used in SELECT statement, its also used in UPDATE, DELETE etc. 
    Q. How to select Specific columns in select?
  •  To write Specific columns in select 
     " select column1,column2 from table name
        where Id;"    
             For Example:


        QWhat is an ALIASES in SQL ?
  • It is often used to make column names more readable.
  • It  is created with As Keyword.
  • Syntax: For Column  
       select column_name AS alias_name
       from table_name;

      For Row
        select column_name(s) 
       from table_name AS alias_name ;

       For Example:



Q. Explain the difference between inner vs left vs right ? 

  • INNER JOIN: INNER JOIN keywords just select records that have matching values in both tables like 
  •                                
  • Syntax: 
         select column_name(s)

from table1

inner join table2

on table1.column_name=

table.column_name;

  • For Example:
         select 
         cust.Id,
         cust.FirstName,
         cust.LastName,
 address.Address 
 from tblCustomer1 as cust 
         inner join tblAddress1 as address 
 on cust.Id=address.Customer_fk

                          

                • LEFT JOIN: LEFT JOIN keyword returns all records from the left table(table1), and the matching record table from right table.

                         Example:
                          select 
                         cust.Id,
                         cust.FirstName,
                         cust.LastName,
                 address.Address 
                 from tblCustomer1 as cust 
                         left join tblAddress1 as address 
                 on cust.Id=address.Customer_fk



                • RIGHT JOIN: RIGHT JOIN keyword returns all records from the right table(table2), and the matching record table from left table.
                       
                        Example 
                         select 
                         cust.Id,
                         cust.FirstName,
                         cust.LastName,
                 address.Address 
                 from tblCustomer1 as cust 
                         right join tblAddress1 as address 
                 on cust.Id=address.Customer_fk


                Thank You...













                ليست هناك تعليقات:

                إرسال تعليق