Posts

Showing posts from June, 2019

Insert and Get value multi checkbox box list using MVC 5

Insert and Get value multi checkbox box list using MVC 5 [HTTPGET] =========================  [HttpGet]         public ActionResult UserProfile()     // Show form data page load time         {             ProfileViewModel obj = new ProfileViewModel();             string username = Convert.ToString(Session["Username"]);             SignUp objsignup = db.signUp.Where(x => x.Username == username).FirstOrDefault();  List<Hobbies> objSelectedHobbies = FillHobbies();             if (!string.IsNullOrEmpty(objsignup.Hobbies))             {                             string s = objsignup.Hobbies;                 string[] values = s.Split(','); ...

When should we use a unique key

Image
SQL UNIQUE Constraint The UNIQUE constraint ensures that all values in a column are different. Both the UNIQUE and PRIMARY KEY constraints provide a guarantee for uniqueness for a column or set of columns. A PRIMARY KEY constraint automatically has a UNIQUE constraint. However, you can have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table. ======================== Q and A Question :  Since primary key and unique is similar. I have trouble grasping the concept of the two. I know primary key doesnt accept null and unique key accepts a null once. Since a null value is a unique value so it can be only accepted once. But the idea of primary key is having a uniqueness in every row. which a unique key also do. thats why im asking when is it proper to use primary key over unique key and vice versa. Answer :  A UNIQUE constraint is similar to PRIMARY key, but you can have more than one UNIQUE constraint per table. When you declare ...

Get Top 3rd salary using MS SQL server

You can get any number of Top salary by using below query WITH CTE AS (     SELECT EmpID, EmpName, EmpSalary,            RN = ROW_NUMBER() OVER (ORDER BY EmpSalary DESC)     FROM dbo.Salary ) SELECT EmpID, EmpName, EmpSalary FROM CTE WHERE RN =  @NthRow If somebody ask for Top 3rd salary, then i'll replace 3 to  @NthRow  then i'll execute query. and then i'll get top 3rd salary.