41.Explain Union, Union all, what is the difference between them?Used to combine results of two or more SQL statements provided that the datatypes of respective columns in all the queries match exactly or are implicitly convertible. ‘Union’ removes duplicate rows but ‘Union all’ does not. 42.What alternatives do you have for Union?You can use the temp table. You can use the ‘OR’ clause in the SQL statement. 43.Can u use select into statement in a Union?
Possible if it is stated in the first select statement.
Eg: Select * into tab1 from A1 Union Select * from A2 44.I am having a table A with 500 rows, I write select * from A union select * from A, what will be the output? (i.e. How many rows will be displayed) ?Same number of rows but if you use the union all command you will get the double number of records. 45.Can u change the data type of a column when there are records, without dropping the table?In real scenario you can never update the data type of a column but in 11.9.x if you are having sa role, you can go to syscolumns and can update the type column without dropping the table or deleting the table but this is very dangerous because it may corrupt the Sybase storage files. Just think what will happen if you update the data type of char to int or vice-versa. 46.Can u drop a column if it is not the last column of the table?Yes you can by same alter table. 47.If I need a few rows from the table, how can I best achieve it?
I – create a view and then call BCP
II – create a tempdb..table and then call BCP. 48.What is the diff between numeric and decimal data type?Only numeric types with a scale of 0 can be used for the IDENTITY column. 49.What is the diff between char and varchar data type?Char is fix length data type and varchar is variable length data type. 50.What is the diff between money and numeric?Money can store a number up to 4 decimal places only. Numeric can save a number up to 37 decimal places. 51.What is the meaning of precision and scale of a data type?Precision is maximum number of digit you can store in column. We can have 1-38 precision the default is 18 52.What is a cursor? Why should we avoid it? How should we avoid it?By means of cursor, we can address a set of rows individually, one row at a time. A cursor is a pointer that identifies a specific working row within a set. 53.Can I use temporary tables in cursors?
Eg : create proc p1
as begin declare @id int select * into #a from an1 declare c1 cursor for select id from #a open c1 fetch c1 into @id while @@sqlstatus != 2 begin print ‘%1!’,@id fetch c1 into @id end end 54.Why is @@sqlstatus used for?To see the status of sql query executed. 55.Explain what are the diff values of @@ sqlstatus and what do they mean?
56.What is the diff between equi join and natural join?Joins based on equality (=) are called equijoins. Equijoins compare the values in the columns being joined for equality and then include all the columns in the tables being joined in the results. 57.What are constraints/rules/defaults? What is the use?All are used to maintain domain integrity.
58.What is the diff between primary key and unique key?Primary key does not allow null values. Unique key allows only one null value for the specified column in the table. 59.Can we create a non-clustered, non-unique index on the primary key?alter table tt add constraint pk primary key nonclustered (c1) 60.What are constraints? Can I drop constraints? How?
Alter table <table-name> drop constraint <constraint-name>
|