Replicate() function in SQL Server

Replicate() function is one of special function in SQL Server.

When you insert maximum number of characters to name per one column is very difficult.

By using replicate() function is very easy to insert more characters or string to the particular column.

Syntax:

REPLICATE(‘character/string’,integer value)

How many time character/string is repeated, based on the integer value.

Example:

REPLICATE(‘ABC’,30)        // ABC string is repeated 30 number of times.

 


Simple Example:

create database db1
use db1
create table emp(eno int,ename varchar(900),sal int)
insert into emp values(1,REPLICATE(‘A’,890),15000) // A ->is repeated 890 times.
insert into emp values(2,REPLICATE(‘bujji’,40),20000)  // bujji ->is repeated 40 times

Note: The ename should not cross the 900 bytes, because max size was mentioned ename(900) in a table.

select * from emp


replicate_function

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s