SQL SERVER MANAGEMENT STUDIO (SSMS)
TYPE OF DATATYPE
USING SELECT STATEMENT CREATE TABLE
|TYPES OF CONSTRAINTS
|CREATE CLUSTER INDEX
CREATE NON CLUSTER INDEX
INSERT RECORDS USING SELECT STATEMENT
USING SELECT INSERT TABLE
UPDATE RECORDS USING JOIN
DELETE RECORDS USING JOIN
DIFFERENCE BETWEEN DELETE AND TRUNCATE
DELETE DUPLICATE RECORDS
MULTI ROW SUB QUERIES
[> ALL] More than the highest value returned by the subquery
[< ALL] Less than the lowest value returned by the subquery
[< ANY] Less than the highest value returned by the subquery
[> ANY] More than the lowest value returned by the subquery
[= ANY] Equal to any value returned by the subquery (same as IN)
CORRELATED SUB QUERY
|CREATE DATABASE <DatabaseName>ALTER DATABASE <DatabaseName>
ALTER DATABASE oldName MODIFY NAME = newName
DROP DATABASE <DatabaseName>
||Schema is use to separate the group of objects and its used schema wise Login user given rights
|| CREATE Schema <Schema name>
||Once drop all objects in schema only you can able to drop schema
I tried “YYYYMMDD” Float format to Date format.
Declare @date float=19991231
SELECT CASE WHEN ISDATE(CAST(@date AS INT))=1 THEN CONVERT(DATETIME,CAST(CAST(@date AS INT)AS CHAR(10)),102) ELSE NULL END [Date]
I imported some records Excel to Sql server the date format changed to float. I get trouble for tried to update date one table from the Excel table. I searched lot of search engine but the code not work properly. finally i tried my self in the way of above Query then its worked.
DECLARE @SearchStr nvarchar(max)
SET @SearchStr = 'OACM'
CREATE TABLE #Results (ColumnName nvarchar(max), ColumnValue nvarchar(max))
DECLARE @StrResult VARCHAR(MAX)
SET NOCOUNT ON
DECLARE @TableName nvarchar(max), @ColumnName nvarchar(max), @SearchStr2 nvarchar(max)
SET @TableName = ''
SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')
WHILE @TableName IS NOT NULL
SET @ColumnName = ''
SET @TableName =
SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
WHERE TABLE_TYPE = 'BASE TABLE'
AND QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
) = 0
WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
SET @ColumnName =
WHERE TABLE_SCHEMA = PARSENAME(@TableName, 2)
AND TABLE_NAME = PARSENAME(@TableName, 1) AND TABLE_NAME NOT LIKE '%$%'
AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar', 'int', 'decimal')
AND QUOTENAME(COLUMN_NAME) > @ColumnName
IF @ColumnName IS NOT NULL
Set @StrResult='SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630) FROM ' + @TableName + ' (NOLOCK) ' +
' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
INSERT INTO #Results
-- 'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630) FROM ' + @TableName + ' (NOLOCK) ' +
-- ' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
DROP TABLE #Results
we often changes table column and datatype and insert a records. These records need to copy same table or another table .Every changes a updating stored procedure in Insert statement. some time we forgot the changes in stored procedure. To avoid following problem using dynamic Query to get all columns and create a string Insert statement.
ALTER PROCEDURE [dbo].[spGetCopyTable]
@QUERY VARCHAR(MAX) OUTPUT
DECLARE @QUERY nVARCHAR(MAX)
EXEC [dbo].[spGetCopyTable] @TABLE=’LiaRiskLocDtls’, @QUERY= @QUERY
–DECLARE @TABLE VARCHAR(50)=’LiabilityMain’
–DECLARE @QUERY VARCHAR(MAX)
DECLARE @COLUMN NVARCHAR(MAX)
DECLARE @SELECT VARCHAR(MAX)
DECLARE @QRY NVARCHAR(MAX)
SET @QRY=N’SELECT @COLUMN=STUFF((
SELECT ”,[”+C.NAME+”]” FROM SYS.columns C INNER JOIN SYS.tables T ON T.object_id=C.object_id
WHERE T.name=”’+@TABLE+”’ FOR XML PATH(””)),1,1,””)’
exec sp_executesql @QRY, N’@COLUMN VARCHAR(MAX) out’, @COLUMN out
SET @SELECT=’SELECT ‘+REPLACE(@COLUMN,’QuotationNo’,’@NQuotationNo’)
SET @SELECT=@SELECT+’ FROM ‘+@TABLE+’ PM WHERE QuotationNo=@SQuotationNo ‘
SELECT @QUERY=’INSERT INTO DBO.’+@TABLE+’ (‘+@COLUMN+’)’ + @SELECT
SELECT ID,(SELECT MIN([DATE]) FROM (VALUES(col1),(col2),(col3)) x([DATE])) MINDATE FROM Tablename
- What is RDBMS?
- What are the Properties of the Relational Tables?
- What is Normalization?
- What is De-normalization?
- How is ACID property related to Database?
- What are the Different Normalization Forms?
- What is the Difference between a Function and a Stored Procedure?
- What is subquery? Explain the Properties of a Subquery?
- What are Different Types of Join?
- What are Primary Keys and Foreign Keys?
- What is User-defined Functions? What are the types of User-defined Functions that can be created?
- What is an Identity?
- What is DataWarehousing?
- What languages BI uses to achieve the goal?
- What is Standby Servers? Explain Types of Standby Servers.
- What is Dirty Read?
- Why can’t I use Outer Join in an Indexed View?
- What is the Correct Order of the Logical Query Processing Phases?
- Which TCP/IP port does the SQL Server run on? How can it be Changed?
- What are the Difference between Clustered and a Non-clustered Index?
- What are the Different Index Configurations a Table can have?
- What are Different Types of Collation Sensitivity?
- What is OLTP (Online Transaction Processing)?
- What’s the Difference between a Primary Key and a Unique Key?
- What is Difference between DELETE and TRUNCATE Commands?
- What are Different Types of Locks?
- What are Pessimistic Lock and Optimistic Lock?
- When is the use of UPDATE_STATISTICS command?
- What is the Difference between a HAVING clause and a WHERE clause?
- What is Connection Pooling and why it is Used?
- What are the Properties and Different Types of Sub-Queries?
- What are the Authentication Modes in SQL Server? How can it be Changed?
- Which Command using Query Analyzer will give you the Version of SQL Server and Operating System?
- What is an SQL Server Agent?
- Can a Stored Procedure call itself or a Recursive Stored Procedure? How many levels of SP nesting is possible?
- What is Log Shipping?
- Name 3 ways to get an Accurate Count of the Number of Records in a Table?
- What does it mean to have QUOTED_IDENTIFIER ON? What are the Implications of having it OFF?
- What is the Difference between a Local and a Global Temporary Table?
- What is the STUFF Function and How Does it Differ from the REPLACE Function?
- What is PRIMARY KEY?
- What is UNIQUE KEY Constraint?
- What is FOREIGN KEY?
- What is CHECK Constraint?
- What is NOT NULL Constraint?
- What is the difference between UNION and UNION ALL?
- What is B-Tree?
- How to get @@ERROR and @@ROWCOUNT at the Same Time?
- What is a Scheduled Job or What is a Scheduled Task?
- What are the Advantages of Using Stored Procedures?
- What is a Table Called, if it has neither Cluster nor Non-cluster Index? What is it Used for?
- Can SQL Servers Linked to other Servers like Oracle?
- What is BCP? When is it Used?
- What Command do we Use to Rename a db, a Table and a Column?
- What are sp_configure Commands and SET Commands?
- How to Implement One-to-One, One-to-Many and Many-to-Many Relationships while Designing Tables?
- What is Difference between Commit and Rollback when Used in Transactions?
- What is an Execution Plan? When would you Use it? How would you View the Execution Plan?
- What is Difference between Table Aliases and Column Aliases? Do they Affect Performance?
- What is the difference between CHAR and VARCHAR Datatypes?
- What is the Difference between VARCHAR and VARCHAR(MAX) Datatypes?
- What is the Difference between VARCHAR and NVARCHAR datatypes?
- Which are the Important Points to Note when Multilanguage Data is Stored in a Table?
- How to Optimize Stored Procedure Optimization?
- What is SQL Injection? How to Protect Against SQL Injection Attack?
- How to Find Out the List Schema Name and Table Name for the Database?
- What is CHECKPOINT Process in the SQL Server?
- How does Using a Separate Hard Drive for Several Database Objects Improves Performance Right Away?
- How to Find the List of Fixed Hard Drive and Free Space on Server?
- Why can there be only one Clustered Index and not more than one?
- What is Difference between Line Feed (\n) and Carriage Return (\r)?
- Is It Possible to have Clustered Index on Separate Drive From Original Table Location?
- What is a Hint?
- How to Delete Duplicate Rows?
- Why the Trigger Fires Multiple Times in Single Login?
- What is Aggregate Functions?
- What is Use of @@ SPID in SQL Server?
- What is the Difference between Index Seek vs. Index Scan?
- What is the Maximum Size per Database for SQL Server Express?
- How do We Know if Any Query is Retrieving a Large Amount of Data or very little data?
- What is the Difference between GRANT and WITH GRANT while Giving Permissions to the User?
- How to Create Primary Key with Specific Name while Creating a Table?
- What is T-SQL Script to Take Database Offline – Take Database Online
- How to Enable/Disable Indexes?
- Can we Insert Data if Clustered Index is Disabled?
- How to Recompile Stored Procedure at Run Time?
- Is there any Performance Difference between IF EXISTS (Select null from table) and IF EXISTS (Select 1 from table)?
- What is Difference in Performance between INSERT TOP (N) INTO Table and Using Top with INSERT?
- Does the Order of Columns in UPDATE statements Matter?
- What are the basic functions for master, msdb, model, tempdb and resource databases?
- What is the Maximum Number of Index per Table?
- Explain Few of the New Features of SQL Server 2008 Management Studio
- Explain IntelliSense for Query Editing
- Explain MultiServer Query
- Explain Query Editor Regions
- Explain Object Explorer Enhancements
- Explain Activity Monitors
- What is Service Broker?
- Where are SQL server Usernames and Passwords Stored in the SQL server?
- What is Policy Management?
- What is Database Mirroring?
- What are Sparse Columns?
- What does TOP Operator Do?
- What is CTE?
- What is MERGE Statement?
- What is Filtered Index?
- Which are the New Data Types Introduced in SQL SERVER 2008?
- What are the Advantages of Using CTE?
- How can we Rewrite Sub-Queries into Simple Select Statements or with Joins?
- What is CLR?
- What are Synonyms?
- What is LINQ?
- What are Isolation Levels?
- What is Use of EXCEPT Clause?
- What is XPath?
- What is NOLOCK?
- What is the Difference between Update Lock and Exclusive Lock?
- How will you Handle Error in SQL SERVER 2008?
- What is RAISEERROR? What is RAISEERROR?
- How to Rebuild the Master Database?
- What is the XML Datatype?
- What is Data Compression?
- What is Use of DBCC Commands?
- How to Copy the Tables, Schema and Views from one SQL Server to Another?
- How to Find Tables without Indexes?
- How to Copy Data from One Table to Another Table?
- What is Catalog Views?
- What is PIVOT and UNPIVOT?
- What is a Filestream?
- What is SQLCMD?
- What do you mean by TABLESAMPLE?
- What is ROW_NUMBER()?
- What are Ranking Functions?
- What is Change Data Capture (CDC) in SQL Server 2008?
- How can I Track the Changes or Identify the Latest Insert-Update-Delete from a Table?
- What is the CPU Pressure?
- How can I Get Data from a Database on Another Server?
- What is the Bookmark Lookup and RID Lookup?
- What is Difference between ROLLBACK IMMEDIATE and WITH NO_WAIT during ALTER DATABASE?
- What is Difference between GETDATE and SYSDATETIME in SQL Server 2008?
- How can I Check that whether Automatic Statistic Update is Enabled or not?
- How to Find Index Size for Each Index on Table?
- What is the Difference between Seek Predicate and Predicate?
- What are Basics of Policy Management?
- What are the Advantages of Policy Management?
- What are Policy Management Terms?
- What is the ‘FILLFACTOR’?
- Where in MS SQL Server is ’100’ equal to ‘0’?
- What are Points to Remember while Using the FILLFACTOR Argument?
- What is a ROLLUP Clause?
- What are Various Limitations of the Views?
- What is a Covered index?
- When I Delete any Data from a Table, does the SQL Server reduce the size of that table?
- What are Wait Types?
- How to Stop Log File Growing too Big?
- If any Stored Procedure is Encrypted, then can we see its definition in Activity Monitor?
- What is Data Warehousing?
- What is Business Intelligence (BI)?
- What is a Dimension Table?
- What is Dimensional Modeling?
- What is a Fact Table?
- What are the Fundamental Stages of Data Warehousing?
- What are the Different Methods of Loading Dimension tables?
- Describes the Foreign Key Columns in Fact Table and Dimension Table?
- What is Data Mining?
- What is the Difference between a View and a Materialized View?
- What is OLTP?
- What is OLAP?
- What is the Difference between OLTP and OLAP?
- What is ODS?
- What is ER Diagram?
- What is ETL?
- What is VLDB?
- Is OLTP Database is Design Optimal for Data Warehouse?
- If denormalizing improves Data Warehouse Processes, then why is the Fact Table is in the Normal Form?
- What are Lookup Tables?
- What are Aggregate Tables?
- What is Real-Time Data-Warehousing?
- What are Conformed Dimensions?
- What is a Conformed Fact?
- How do you Load the Time Dimension?
- What is a Level of Granularity of a Fact Table?
- What are Non-Additive Facts?
- What is a Factless Facts Table?
- What are Slowly Changing Dimensions (SCD)?
- What is Hybrid Slowly Changing Dimension?
- What is BUS Schema?
- What is a Star Schema?
- What Snow Flake Schema?
- Differences between the Star and Snowflake Schema?
- What is Difference between ER Modeling and Dimensional Modeling?
- What is Degenerate Dimension Table?
- Why is Data Modeling Important?
- What is a Surrogate Key?
- What is Junk Dimension?
- What is a Data Mart?
- What is the Difference between OLAP and Data Warehouse?
- What is a Cube and Linked Cube with Reference to Data Warehouse?
- What is Snapshot with Reference to Data Warehouse?
- What is Active Data Warehousing?
- What is the Difference between Data Warehousing and Business Intelligence?
- What is MDS?
- Explain the Paradigm of Bill Inmon and Ralph Kimball.
Paras Doshi has submitted 21 interesting question and answers for SQL Azure.
1.What is SQL Azure?
2.What is cloud computing?
3.How is SQL Azure different than SQL server?
4.How many replicas are maintained for each SQL Azure database?
5.How can we migrate from SQL server to SQL Azure?
6.Which tools are available to manage SQL Azure databases and servers?
7.Tell me something about security and SQL Azure.
8.What is SQL Azure Firewall?
9.What is the difference between web edition and business edition?
10.How do we synchronize On Premise SQL server with SQL Azure?
11.How do we Backup SQL Azure Data?
12.What is the current pricing model of SQL Azure?
13.What is the current limitation of the size of SQL Azure DB?
14.How do you handle datasets larger than 50 GB?
15.What happens when the SQL Azure database reaches Max Size?
16.How many databases can we create in a single server?
17.How many servers can we create in a single subscription?
18.How do you improve the performance of a SQL Azure Database?
19.What is code near application topology?
20.What were the latest updates to SQL Azure service?
21.When does a workload on SQL Azure get throttled?