different SQL Server date formats

  Below is a list of formats and an example of the output.  The date used for all of these examples is “2006-12-30 00:38:54.840”. DATE ONLY FORMATS Format # Query Sample 1 select convert(varchar, getdate(), 1) 12/30/06 2 select convert(varchar, getdate(), 2) 06.12.30 3 select convert(varchar, getdate(), 3) 30/12/06 4 select convert(varchar, getdate(), 4) 30.12.06

[Solved]: Suspect database in sql server 2012

To solve this problem you need microsoft sql server management studio. Open with administrator access. Now open new query and use the below query. Replace my_db with your database. EXEC sp_resetstatus my_db; ALTER DATABASE my_db SET EMERGENCY DBCC checkdb(my_db) ALTER DATABASE my_db SET SINGLE_USER WITH ROLLBACK IMMEDIATE DBCC CheckDB (my_db , REPAIR_ALLOW_DATA_LOSS) ALTER DATABASE my_db

Difference BETWEEN GETDATE And SYSDATETIME Function In SQL Server

Difference b/w GETDATE And SYSDATETIME Function In SQL Server GETDATE() SELECT GETDATE() AS DATE GETDATE() RETURN ONLY CURRENT DATABASE SYSTEM TIME STAMP  AS A DATETIME VALUE WITHOUT WITHOUT TIME ZONE OFFSET.THIS VALUE IS DERIVED FROM OPERATING SYSTEM OF THE COMPUTER ON WHICH THE INSTANCE OF SQL SERVER IS RUNNING SYSDATETIME() RETURN DATETIME () VALUE THAT CONTAIN

Performance Tuning SQL Server

Below points explain some tips for better SQL Server performance. 1. Always have a primary key on every table that you create. 2. Identify those columns which acts as key columns on the table for search. Keep those keys as Non-Clustered indexes. 3. Specify “SET NOCOUNT ON” on each stored procedure that you create, saves

Reset table auto increment column in ms sql server

Reset table auto increment column in ms sql server If we want to reset the auto increment value of any table to any other value than default value, we need to use DBCC query. To use DBCC query you must open sql server management studio with Administrator permission. Check the below query: DBCC CHECKIDENT(‘tblUser‘, RESEED, 1000)

Fetching data from two or more tables(Joining of tables)

Selecting data from two or more tables(Joining of tables) Hello Friends, today we will learn how to select data(records) from more than one table. For this purpose we will use joining of tables. Joining simply join one or two or more than two tables by some conditions as per need. One there is a joining between one

create a cursor in ms sql server

create a cursor in ms sql server Cursor is used to fetch records(rows) from any table sequentially and records can be manipulated, calculated as per your need. To create a cursor use this sql query: declare cursor_name cursor for select id from tbl_Category open cursor_name fetch next from cursor_name into @Id while @@fetch_status=0 begin insert into table_name(id) values

introduction of store procedure in mssql server

Hello friend, It is very bad habit and difficult to write separate sql query for each operation in sql query. The best solution for this problem is procedure . Procedure is similar to function which we will learn in next chapter, is collection of code which can be executed at any time. To create a procedure open