Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
20 views

SQL ServerScript3

Script of Sql
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

SQL ServerScript3

Script of Sql
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

/*

Rename Table: If i want to modify the table name we have to use system procedure
Syntax: SP_RENAME 'OLDTABLENAME','NEWTABLENAME'
*/
sELECT * FROM FirstTable

SP_RENAME 'FirstTable','FirstTable_1'

select * from FirstTable_1

/*
Rename Column: If i want to modify the column name we have to use system procedure
Syntax: SP_RENAME 'OLDTABLENAME.OLDCOLUMNNAME','NEWCOLUMNNAME'
*/
select * from FirstTable_1

SP_RENAME 'FirstTable_1.[product id]','Product_Id'

/*
Alter: If you want to modify the structure of the table use ALTER command

There are different ways to use ALTER command


1) Change the data type/Size for any column
2) Add a new column to the existing table
3) Drop a column to the existing table

1) Change the data type/Size for any column: If you want to change the
datatype/size to the existing column use ALTER command
Syntax: Alter table existingtablename alter column existingcolumnname newdatatype
size
*/
select * from FirstTable_1

alter table FirstTable_1 alter column product_id bigint

--Note: If we want to see the table information select the table first and click on
ALT+F1

Alter table FirstTable_1 alter column [product name] varchar(10)--Increase/Decrease


the size of any column

/*
Add Column: Add new column to the existing table use ALTER command
Syntax: Alter table existingtablename add newcolumnname datatype size
*/
select * from FirstTable_1

Alter table FirstTable_1 add Dept_No int

/*
Drop column: If we want to delete the column permenantly from the table use ALTER
command
Syntax: Alter table existingtablename drop column columnname
*/
Select * from FirstTable_1

alter table FirstTable_1 drop column dept_no


/*
DROP: If you want to delete the object permenantly from the server use DROP
Syntax: DROP Table existingtablename
*/
Drop table FirstTable_1

Create table [FirstTable]([Product Id] int,[Product Name] varchar(5),[Product Date]


date,Sales decimal(7,4),Bonus float)

/*
TRUNCATE: Delete all the records from the existing table use TRUNCATE
Syntax: Truncate table existingtablename
*/
Select * from [FirstTable]

Truncate table [FirstTable]

/*
DML: The full form of DML is Data Manipulation Language. It will modify the
existing table data
DML commands are INSERT,UPDATE,DELETE

INSERT:If you want to insert new records to the existing table use INSERT command

There are multiple ways to INSERT a records into the table


1) Row wise insertion
2) Bulk insertion to the existing table

1) Row wise insertion:It will insert 1 record once at a time


Syntax: Insert into existingtablename (col1,col2,col3,...)
values(val1,val2,val3,....)

*/
Select * from [FirstTable]

Insert into [FirstTable]([Product Id],[Product Name],[Product Date],Sales,Bonus)


values(1,'xyz','2021-11-27',250,2000)

select * from [FirstTable]


Insert into [FirstTable]([Product Id],[Product Name],[Product Date])
values(2,'pqr','2015-06-22')

Insert into [FirstTable]([Product Name],[Product Id],[Product Date])


values('abc',3,'2017-04-15')

Insert into [FirstTable]([Product Name],[Product Id],[Product Date])


values('qaz',4,'2012-02-21'),('wsx',5,'2014-07-22')

Insert into [FirstTable] values(6,'edc','2018-08-26',360,500)

select * from [FirstTable]

You might also like