question

rimjhim2022 avatar image
rimjhim2022 asked

Create T-SQL Script to generate a DDL based on the table already existing in sql server.

i am trying to create SP or sql script which will read column name from a Master table

and generate a new child table with same data type but column name will get trim.


for example:


CREATE TABLE MASTER
(
P_GO_LIVE_DATE VARCHAR(50),
PARENT VARCHAR(50),
CAPEX_FORCAST_COST VARCHAR(40),
SKILLS VARCHAR(25),
Relase_CALENDER DATE
)


Than the script should generate DDL like


CREATE TABLE CHILD
(
LIV_DAT_DSC VARCHAR(50),
PAR_DSC VARCHAR(50),
CAP_FOR_COS_DSC VARCHAR(40),
SKI_DSC VARCHAR(25),
REL_CAL_DAT DATE
)


Rule:

if col name is consists of underscore(_) than it will take 3 character before each character.

if it is less than 3 character it discard.

for example

P_GO_LIVE_DATE VARCHAR(50), column in master table
here child table discard P completely and create column LIV_DAT_DSC VARCHAR(50).


any varchar column in Master table , will be created in Child table with Suffic DSC, similarly any date type in master have suffix DAT in child table
t-sqlsql2014
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.