SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


would need some help


would need some help

Author
Message
hillerz19
hillerz19
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 34
i would need to change the service code in the service table to be 2characters followed by 2 digits. For existing services,Add an 'X' to the beginning of each serviceCode. Any affected tables(s) should also changed accordingly.

this would be my table:

CREATE TABLE ClientTable
(
clientID char(5) NOT NULL,
clientName Char(30) NOT NULL,
clientAddress char(50) NOT NULL,
clientContact Numeric(8) NOT NULL,
CONSTRAINT ClientTablePK PRIMARY KEY(clientID),
CHECK(clientID like '[A-Z][0-9][0-9][0-9][A-Z]'),
CHECK (clientContact like '[6][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' OR
clientContact like'[8][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' OR
clientContact like'[9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')
);

CREATE TABLE CaseTable
(
referenceNum int NOT NULL IDENTITY(100000,1),
startDate DATETIME NOT NULL,
endDate DATETIME NULL,
caseDetail Char(255) NOT NULL,
caseType Char(255) NOT NULL DEFAULT'copyright and trademark',
clientID Char(5) NOT NULL,
CONSTRAINT CaseTablePK PRIMARY KEY(referenceNum),
CONSTRAINT ClientTableFK FOREIGN KEY(clientID)
REFERENCES ClientTable(clientID),
CONSTRAINT caseTypeValues CHECK(caseType LIKE 'intellectual property enforcement' OR
caseType LIKE'copyright and trademark' OR caseType LIKE'patent and industrial design' OR
caseType LIKE'trade secret' OR caseType LIKE 'risk management' OR
caseType LIKE'litigation'),
CONSTRAINT clientIDValues CHECK(clientID LIKE '[A-Z][0-9][0-9][0-9][A-Z]')
);

CREATE TABLE ServiceTable
(
serviceCode Char(3) NOT NULL,
serviceDescription Char(255) NOT NULL,
minCharge Money NOT NULL,
CONSTRAINT ServiceTablePK PRIMARY KEY(serviceCode),
CONSTRAINT serviceCodeValues CHECK(serviceCode like '[C][0-9][0-9]' OR
serviceCode like'[E][0-9][0-9]' OR
serviceCode like'[O][0-9][0-9]'),
CONSTRAINT minChargeValues CHECK(minCharge BETWEEN '500' AND '1000000')
);

CREATE TABLE ServiceRenderedTable
(
referenceNum int NOT NULL IDENTITY(100000,1),
serviceDate DATETIME NOT NULL,
serviceCode Char(3) NOT NULL,
actualServiceCost Money NOT NULL ,
CONSTRAINT ServiceRenderedTablePK PRIMARY KEY(referenceNum,serviceDate),
CONSTRAINT CaseTableFK FOREIGN KEY(referenceNum)
REFERENCES CaseTable(referenceNum),
CONSTRAINT ServiceTableFK FOREIGN KEY(serviceCode)
REFERENCES ServiceTable(serviceCode),
CONSTRAINT actualServiceCost_positive CHECK (actualServiceCost>0.00)
);

appriciate if anyone could help me. Thanks
Sean Lange
Sean Lange
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62681 Visits: 17959
This looks a LOT like homework. What have you tried? What do you think you need to change?

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
hillerz19
hillerz19
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 34
Hi Sean Lange,

I am a new to SQL. And i try doing looking at a book but gives me error and lots of it. i am not sure how to start
Sean Lange
Sean Lange
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62681 Visits: 17959
hillerz19 (10/10/2012)
Hi Sean Lange,

I am a new to SQL. And i try doing looking at a book but gives me error and lots of it. i am not sure how to start


OK so what do you think needs to be changed? What have you tried so far that didn't work? I could provide the script for this fairly easily but then you don't learn how to solve it.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
hillerz19
hillerz19
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 34
Hi Sean Lange,

This is my coding so far but allot of errors:

ALTER TABLE ServiceTable
ALTER COLUMN serviceCode char(4) NOT NULL,
ALTER TABLE CaseTable
DROP CONSTRAINT serviceCodeValues,
ALTER TABLE CaseTable
ALTER serviceCode DROP DEFAULT,
Jason-299789
Jason-299789
SSCarpal Tunnel
SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)

Group: General Forum Members
Points: 4995 Visits: 3232
hillerz19 (10/10/2012)
Hi Sean Lange,

This is my coding so far but allot of errors:

ALTER TABLE ServiceTable
ALTER COLUMN serviceCode char(4) NOT NULL,
ALTER TABLE CaseTable
DROP CONSTRAINT serviceCodeValues,
ALTER TABLE CaseTable
ALTER serviceCode DROP DEFAULT,



Firstly on the CaseTable I dont see a column called servicecode, or a constraint called servicecodevalues so the code will fail.

They are however there is a Constraint called ServiceCodeValues on the ServiceTable, but no Default value, You also have an FK reference on the serviceRenderedTable which uses the Servicecode on the Servicetable.

1) Drop FK Constraint on ServiceRenderedTable
2) Drop servicecovevalues Constraint on ServiceTable
3) Alter Both Servicecode Column in Servicetable AND ServiceRenderedTable
4) Update data in BOTH tables for new pattern, adding an X to the beginning of the servicecode column
5) Reapply the Check Constraint on the Service table.
6) Reapply FK Constraint on the ServiceRenderedTable

One thing you an do is change the check to be : Check(serviceCode like '[X][C|E|O][0-9][0-9]') which is bit more readable.

Make sure you test this in a dev environment.

I dont think I've missed any steps.

_________________________________________________________________________
SSC Guide to Posting and Best Practices
hillerz19
hillerz19
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 34
hi,
Thanks Allot. I would follow your steps and wish i could make it out.

for to your question,I declare a CONSTRAINT ServiceCodeValues in my serviceTAble. and not sure if i drop me contraint by the Constraint name or by the column.
Jason-299789
Jason-299789
SSCarpal Tunnel
SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)

Group: General Forum Members
Points: 4995 Visits: 3232
I'm happy to have a look at the code you create and give it a sanity check.

In response to your question, you need to drop it by the constraint name, If you goto ssms and locate the constraint on the table that you want to drop, right click and script as drop you'll see how it should be dropped.

I would also consider using a naming standard for the constraints, I personally use the following prefixes

DF : Default
CK : Check
FK : ForeignKey
PK : PrimaryKey
UQ : Unique

Such that the name of the Check constraint on the Servicetable for serviceCode would read

CK_ServiceTable_ServiceCode

The FK name would be

FK_ServiceRenderedTable_ServiceTable_ServiceCode

That way I can tell what a constraint is doing and which column/object is affected without having to script the constraint.

_________________________________________________________________________
SSC Guide to Posting and Best Practices
kapil_kk
kapil_kk
SSCertifiable
SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)

Group: General Forum Members
Points: 5322 Visits: 2767
gud one Jason.....

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
hillerz19
hillerz19
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 34
Thanks Allot Old Hand,

I am just following a book for the coding. Would follow the what you have suggested. And thanks for the steps. It does helps me on my way but still having error. will try on my own with the steps till i drop.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search