SQL Queries for different operation on Table

SQL Queries for different operation   on Table


Create New Table

Create table Test
(
id int identity,
Name Varchar(34) not null,
Phone Varchar(10),
is_active bit default 1
)

Add new column to Existing Table

alter table test Add  address varchar(32)

 Drop column from Existing Table

alter table test drop column address

Add Primary key on Existing table

alter table test add constraint pr primary key (id)

Drop Constraint like (Primary Key, foreign key) from Existing Table

alter table TEST  drop constraint pr

Include row number column in select Query

select ROW_NUMBER() OVER (ORDER BY id ) AS RowNumber, * from test

 Change Data Type of column in Table

alter table test alter column phone int


Change name of column in Table

sp_rename 'test.phone' , 'contact'

Change Name of Table

sp_rename test,test2


Comments

Popular posts from this blog

Create and save QR code in asp.net with C#

Change text of RadGrid Header Dynamically

Telerik Radwindow Open on Button Click