Posts

sqlserver material 4

What is Difference between Table Aliases and Column Aliases? Do they Affect Performance? Usually, when the name of the table or column is very long or complicated to write, aliases are used to refer them. e.g. SELECT VeryLongColumnName col1 FROM VeryLongTableName tab1 In the above example, col1 and tab1 are the column alias and table alias, respectively. They do not affect the performance at all. What is the difference between CHAR and VARCHAR Datatypes? VARCHARS are variable length strings with a specified maximum length. If a string is less than the maximum length, then it is stored verbatim without any extra characters, e.g. names and emails. CHARS are fixed-length strings with a specified set length. If a string is less than the set length, then it is padded with extra characters, e.g. phone number and zip codes. For instance, for a column which is declared as VARCHAR(30) and populated with the word ‘SQL Server,’ only 10 bytes will be stored in it. However, if we ha...

sqlserver material 3

What’s the Difference between a Primary Key and a Unique Key? Both primary key and unique key enforce uniqueness of the column on which they are defined. But by default, the primary key creates a clustered index on the column, whereas unique key creates a non-clustered index by default. Another major difference is that primary key doesn’t allow NULLs, but unique key allows one NULL only. ( Read more here ) What is Difference between DELETE  and TRUNCATE Commands? Delete command removes the rows from a table on the basis of the condition that we provide with a WHERE clause. Truncate will actually remove all the rows from a table, and there will be no data in the table after we run the truncate command. TRUNCATE TRUNCATE is faster and uses fewer system and transaction log resources than DELETE. (Read all the points below) TRUNCATE removes the data by deallocating the data pages used to store the table’s data, and only the page deallocations are recorde...

sqlserver material 2

of rows in the second table. The common example is when company wants to combine each product with a pricing table to analyze each product at each price. Inner Join A join that displays only the rows that have a match in both joined tables is known as inner Join. This is the default type of join in the Query and View Designer. Outer Join A join that includes rows even if they do not have related rows in the joined table is an Outer Join. You can create three different outer join to specify the unmatched rows to be included: Left Outer Join: In Left Outer Join, all the rows in the first-named table, i.e. “left” table, which appears leftmost in the JOIN clause, are included. Unmatched rows in the right table do not appear.    Right Outer Join: In Right Outer Join, all the rows in the second-named table, i.e. “right” table, which appears rightmost in the JOIN clause are included. Unmatched rows in the left table are not included. Full Outer J...