Thursday, November 15, 2018

sql server important query

1. Reset the auto generated filed in sql server .


  DBCC CHECKIDENT (table_name, RESEED, 0)



2. Add New column in sql server database by query.



ALTER TABLE  table_Name ADD column_Name datatype NULL ; 


3. Rename Column name in sql server.


sp_rename 'tableName.old_column_Name', 'New_Column_Name', 'COLUMN';



4. Change datatype of particular column in sql server

ALTER TABLE table_Name  ALTER COLUMN Column_Name New_datatype(like bit,datetime);


5. delete particular column from table in sql server


ALTER TABLE table_Name DROP COLUMN column_Name(which you want to delete or remove from table)


6. Remove/Delete more then one column from table in sql server


ALTER TABLE table_Name DROP COLUMN Column1,Column2,...


7. How to active current window for write query


USE Database_Name

8. How to get list of tables in particular database.


SELECT
  *
FROM
  kls.INFORMATION_SCHEMA.TABLES;
GO

9. How to convert date time into string.



select convert(varchar, GETDATE(), 0) as date_In_String



10. How to local server in desktop


(LocalDb)\MSSQLLocalDB  ( Use this as server name)


11. How to change data type of column in sql server.


alter table tbl_Name alter column column_Name new_Datatype


12.  How to copy data from one table to Another table in sql server


insert into tbl_Name1(column_1,column_2) select column_1,column_2 from tbl_Name2


13. How to copy structure of table from one table to another table


select into tblNewMailingAddres from tblMailingAddress


14. How to get structure of table

SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'mytabel'




Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...