Showing posts with label table. Show all posts
Showing posts with label table. Show all posts

13 March 2014

Create a Table in sqlserver



Create a Table:

The following Syntax for Create a table

CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
.........
)

Example

create table tbl_student(Id int,Name varchar(200))

13 February 2014

Delete Duplicate Records in sqlserver Table



Following code is useful to delete duplicate records. The table must have identity column, which will be used to identify the duplicate records. Table in example has ID as Identity Column and Columns which have duplicate data are DuplicateColumn1, DuplicateColumn2 and DuplicateColumn3.

DELETE
FROM MyTable
WHERE ID NOT IN
(
SELECT MAX(ID)
FROM MyTable
GROUP BY DuplicateColumn1, DuplicateColumn2, DuplicateColumn3)

If there is no identity column then

Add Identity Col and perform the operation displayed above and drop Identity Col.