Thursday, 29 August 2013

How Rename any table Drop any column in Sql Server 2008

How  rename any table ,Drop any colum in Sql Server 2008

create database test
use  test
--To create  table, use the following syntax

create table Sqlpractice(Id int identity(100,5) primary key,Name varchar(50),Dob date not null default getdate(),age int not null default 0)

--To rename  table, use the following syntax

sp_rename 'Sqlpractice','testsql'

--To insert into  table, use the following syntax and after insert how to select data
insert into testsql values('Dinesh Ramdeen','','')
insert into testsql values ('Rohit Singh','07/23/1987',24)
Select * from testsql


 --To rename a column in a table, use the following syntax

sp_rename 'testsql.Dob','DateOfBirth','column'

--To add a column in a table, use the following syntax

alter table testSql add  Address varchar(50)

--To change datatype with column in a table, use the following syntax

alter table testsql alter column  Address nvarchar(50)

--To delete a column in a table, use the following syntax

alter table testsql drop column Address

--How to create another table Student  which has the same structure and same data like testSql table

select *  into Student from testSql

--How to create another table Emp  which has the same structure  like testSql table

select *  into Emp from testSql where 0=1




0 comments:

Post a Comment