Hi all, I have a question about user access in MS-SQL.
In our system, we only really have one main user, the SA user. Thats the
user that is used to do all the reads & writes for our application. Works
fine.
A problem arises when our customers want to have access to the DB. Now, we
want to control this so they cant go hacking up thier data and blaming us, s
o
we only allow read only access for report writings etc.
Now our customers are interested in writing views & user defined functions
etc, but we cant seem to find a way to allow users access to create / mod /
delete views & user defined functions, and NOT create / mod / delete DB
tables.
Any ideas / suggestions?
Thanks!> In our system, we only really have one main user, the SA user. Thats the
> user that is used to do all the reads & writes for our application. Works
> fine.
Although this works, it doesn't make it right. The Best Practice in SQL
Server is to never use 'sa' for routine database access.
> Now our customers are interested in writing views & user defined functions
> etc, but we cant seem to find a way to allow users access to create / mod
> /
> delete views & user defined functions, and NOT create / mod / delete DB
> tables.
You can allow users to create objects in only their own schema by granting
the desired object create permissions. Note that only privileged users
(sysdamin, dbo, db_owner and db_ddladmin) can create objects owned by other
users or the 'dbo' schema. Consequently, you could grant CREATE TABLE as
well without compromising data in tables owned by other users.
GRANT
CREATE VIEW,
CREATE FUNCTION
TO CustomerUser
If those user objects reference your application tables, SELECT permissions
on those tables will be needed.
Hope this helps.
Dan Guzman
SQL Server MVP
"-Ldwater" <Ldwater@.discussions.microsoft.com> wrote in message
news:7C2D9969-BBEF-4469-982B-5AC3B5307656@.microsoft.com...
> Hi all, I have a question about user access in MS-SQL.
> In our system, we only really have one main user, the SA user. Thats the
> user that is used to do all the reads & writes for our application. Works
> fine.
> A problem arises when our customers want to have access to the DB. Now,
> we
> want to control this so they cant go hacking up thier data and blaming us,
> so
> we only allow read only access for report writings etc.
> Now our customers are interested in writing views & user defined functions
> etc, but we cant seem to find a way to allow users access to create / mod
> /
> delete views & user defined functions, and NOT create / mod / delete DB
> tables.
> Any ideas / suggestions?
> Thanks!|||Excellent! Thats just what I needed! Tried it out, and it works just fine
:D
But while were on the subject, could I ask a few more questions?
1) You say that using the SA admin isn't the best way of access the DB
through our application. Is there a specific reason why this is bad?
2) Now that my customers can create their own views etc, I need them to be
able to access user defined functions created by the application. How do I
allow exe permissions on these functions to allow all users to execute them?
Thanks again!
"Dan Guzman" wrote:
> Although this works, it doesn't make it right. The Best Practice in SQL
> Server is to never use 'sa' for routine database access.
>
> You can allow users to create objects in only their own schema by granting
> the desired object create permissions. Note that only privileged users
> (sysdamin, dbo, db_owner and db_ddladmin) can create objects owned by othe
r
> users or the 'dbo' schema. Consequently, you could grant CREATE TABLE as
> well without compromising data in tables owned by other users.
> GRANT
> CREATE VIEW,
> CREATE FUNCTION
> TO CustomerUser
> If those user objects reference your application tables, SELECT permission
s
> on those tables will be needed.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "-Ldwater" <Ldwater@.discussions.microsoft.com> wrote in message
> news:7C2D9969-BBEF-4469-982B-5AC3B5307656@.microsoft.com...
>
>|||> 1) You say that using the SA admin isn't the best way of access the DB
> through our application. Is there a specific reason why this is bad?
For routine application database access, it's best to use an account with no
more permissions than actually needed. Using 'sa' or a sysadmin role member
account is overkill unless your app requires that level of security.
Sysadmin role members have full SQL Server permissions and OS permissions
are limited only by the SQL Server service account.
> 2) Now that my customers can create their own views etc, I need them to be
> able to access user defined functions created by the application. How do
> I
> allow exe permissions on these functions to allow all users to execute
> them?
You can GRANT EXECUTE or SELECT, depending on whether the function is scalar
or table-valued.
GRANT SELECT ON MyTableFunction TO CustomerUser
GRANT EXECUTE ON MyScalarFunction TO CustomerUser
Hope this helps.
Dan Guzman
SQL Server MVP
"-Ldwater" <Ldwater@.discussions.microsoft.com> wrote in message
news:95E53960-B58A-4125-B298-430AAAC1191D@.microsoft.com...[vbcol=seagreen]
> Excellent! Thats just what I needed! Tried it out, and it works just
> fine :D
> But while were on the subject, could I ask a few more questions?
> 1) You say that using the SA admin isn't the best way of access the DB
> through our application. Is there a specific reason why this is bad?
> 2) Now that my customers can create their own views etc, I need them to be
> able to access user defined functions created by the application. How do
> I
> allow exe permissions on these functions to allow all users to execute
> them?
> Thanks again!
> "Dan Guzman" wrote:
>|||Right.. i've added those & all is well.
Just as a closing thought.. is there any way I can declare a 'grant' command
to ALL users, current & future?
Its more than likely that once a view / function has been made, it could be
used by other SQL users that will require access, and even though we control
the number of SQL users, it makes more sence to make a function 'global' /
'public' rather than having to recode to add a new user each time we decide
to add one.
Thanks!|||The Best Practice is to create database roles and grant object permissions
only to roles. You can then control access via role membership. This
greatly simplifies security administration.
Hope this helps.
Dan Guzman
SQL Server MVP
"-Ldwater" <Ldwater@.discussions.microsoft.com> wrote in message
news:6F88596D-0A1A-47FB-B56D-9E37EFF3CC94@.microsoft.com...
> Right.. i've added those & all is well.
> Just as a closing thought.. is there any way I can declare a 'grant'
> command
> to ALL users, current & future?
> Its more than likely that once a view / function has been made, it could
> be
> used by other SQL users that will require access, and even though we
> control
> the number of SQL users, it makes more sence to make a function 'global' /
> 'public' rather than having to recode to add a new user each time we
> decide
> to add one.
> Thanks!
Showing posts with label thats. Show all posts
Showing posts with label thats. Show all posts
Monday, March 19, 2012
Friday, February 24, 2012
design questions
So, I don't have the most design experience... but thats about to change. Ive
got a DB that isn't in even 1st NF and has been in Production for some time.
There are hundreds of Stored Procs already and nobody is about to start
re-writing them. So, Im thinking I need to make use of Views. In this way,
existing SP's can stay the same, new SP's can be written against the new
table structures. Im sure Im not the first one to do this, so, any gotcha's?
Anything I need to have in my mind while I do the redesign so I don't spin my
wheels in the wrong direction and find this approach won't work?
TIA,
ChrisR
Chris,
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures.
Obviously the best scenario would be a redesign to comply with 3rd NF
however it sounds like that is not going to happen. You already have an
abstraction layer to the underlying tables with stored procedures. Why do
you want to use views as well? I'm not saying that views should or should
not be used just trying to better understand your situation.
HTH
Jerry
"ChrisR" <ChrisR@.discussions.microsoft.com> wrote in message
news:6A3B81BB-2AE0-44BD-8BED-09D1F88E1398@.microsoft.com...
> So, I don't have the most design experience... but thats about to change.
> Ive
> got a DB that isn't in even 1st NF and has been in Production for some
> time.
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures. Im sure Im not the first one to do this, so, any
> gotcha's?
> Anything I need to have in my mind while I do the redesign so I don't spin
> my
> wheels in the wrong direction and find this approach won't work?
> --
> TIA,
> ChrisR
|||Depends what you mean by "not in 1NF". If you intend to declare new keys and
constraints then views alone won't stop the legacy code throwing constraint
violation errors. Also, not every view may be updateable.
Triggers on INSTEAD OF views might be an option but you might find that it's
easier to rewrite the procs rather than try to accommodate every one of them
in a trigger.
David Portas
SQL Server MVP
"ChrisR" wrote:
> So, I don't have the most design experience... but thats about to change. Ive
> got a DB that isn't in even 1st NF and has been in Production for some time.
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures. Im sure Im not the first one to do this, so, any gotcha's?
> Anything I need to have in my mind while I do the redesign so I don't spin my
> wheels in the wrong direction and find this approach won't work?
> --
> TIA,
> ChrisR
|||The use of Views would be this:
Lets say we have a table called "Client":
ClientID
LName
FName
Address
Address2
City
City2
State
State2
Child1
Child2
Child3
Child4
Child5
This doesn't look too far some of the tables we have. An option would be to
Rename Client to ClientTable with only 3 columns.
ClientID
LName
FName
Another table named ClientAddress. (More than 1 address can be entered here
if needed.)
ClientID
Address
City
State
And another table called ClientChild
More than 1 child can be entered here
if needed.)
ClientID
Child
And finally, create a view named Client.
Create View Client
as
select * from ClientTable ct
inner join ClientAddress ca on ct.ClientId = ca.ClientId
inner join ClientChild cc on ct.ClientId = cc.ClientID
This is a tactic I've heard used by others, but never done it myself.
TIA,
ChrisR
"ChrisR" wrote:
> So, I don't have the most design experience... but thats about to change. Ive
> got a DB that isn't in even 1st NF and has been in Production for some time.
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures. Im sure Im not the first one to do this, so, any gotcha's?
> Anything I need to have in my mind while I do the redesign so I don't spin my
> wheels in the wrong direction and find this approach won't work?
> --
> TIA,
> ChrisR
|||Chris,
I am working on a major redesign at the moment. My shop also has lots of SPs
and tightly-coupled JSP code. My plan is to redesign the database from
scratch and then refactor the database and its attendant code bit by bit so
that in a year or so we will have completely re-engineered to database. In
other words,
1. Design a new, target schema.
2. Map the old schema to the new schema.
3. Develop a plan to convert "table clusters" from the old to the new schema.
4. Follow the plan.
For example, you may have a "company cluster" that consists of several
tables that handle company information. Convert this cluster from the old
schema to the new schema and rewrite your code base to utilize the new schema.
HTH,
Mike
got a DB that isn't in even 1st NF and has been in Production for some time.
There are hundreds of Stored Procs already and nobody is about to start
re-writing them. So, Im thinking I need to make use of Views. In this way,
existing SP's can stay the same, new SP's can be written against the new
table structures. Im sure Im not the first one to do this, so, any gotcha's?
Anything I need to have in my mind while I do the redesign so I don't spin my
wheels in the wrong direction and find this approach won't work?
TIA,
ChrisR
Chris,
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures.
Obviously the best scenario would be a redesign to comply with 3rd NF
however it sounds like that is not going to happen. You already have an
abstraction layer to the underlying tables with stored procedures. Why do
you want to use views as well? I'm not saying that views should or should
not be used just trying to better understand your situation.
HTH
Jerry
"ChrisR" <ChrisR@.discussions.microsoft.com> wrote in message
news:6A3B81BB-2AE0-44BD-8BED-09D1F88E1398@.microsoft.com...
> So, I don't have the most design experience... but thats about to change.
> Ive
> got a DB that isn't in even 1st NF and has been in Production for some
> time.
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures. Im sure Im not the first one to do this, so, any
> gotcha's?
> Anything I need to have in my mind while I do the redesign so I don't spin
> my
> wheels in the wrong direction and find this approach won't work?
> --
> TIA,
> ChrisR
|||Depends what you mean by "not in 1NF". If you intend to declare new keys and
constraints then views alone won't stop the legacy code throwing constraint
violation errors. Also, not every view may be updateable.
Triggers on INSTEAD OF views might be an option but you might find that it's
easier to rewrite the procs rather than try to accommodate every one of them
in a trigger.
David Portas
SQL Server MVP
"ChrisR" wrote:
> So, I don't have the most design experience... but thats about to change. Ive
> got a DB that isn't in even 1st NF and has been in Production for some time.
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures. Im sure Im not the first one to do this, so, any gotcha's?
> Anything I need to have in my mind while I do the redesign so I don't spin my
> wheels in the wrong direction and find this approach won't work?
> --
> TIA,
> ChrisR
|||The use of Views would be this:
Lets say we have a table called "Client":
ClientID
LName
FName
Address
Address2
City
City2
State
State2
Child1
Child2
Child3
Child4
Child5
This doesn't look too far some of the tables we have. An option would be to
Rename Client to ClientTable with only 3 columns.
ClientID
LName
FName
Another table named ClientAddress. (More than 1 address can be entered here
if needed.)
ClientID
Address
City
State
And another table called ClientChild
if needed.)
ClientID
Child
And finally, create a view named Client.
Create View Client
as
select * from ClientTable ct
inner join ClientAddress ca on ct.ClientId = ca.ClientId
inner join ClientChild cc on ct.ClientId = cc.ClientID
This is a tactic I've heard used by others, but never done it myself.
TIA,
ChrisR
"ChrisR" wrote:
> So, I don't have the most design experience... but thats about to change. Ive
> got a DB that isn't in even 1st NF and has been in Production for some time.
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures. Im sure Im not the first one to do this, so, any gotcha's?
> Anything I need to have in my mind while I do the redesign so I don't spin my
> wheels in the wrong direction and find this approach won't work?
> --
> TIA,
> ChrisR
|||Chris,
I am working on a major redesign at the moment. My shop also has lots of SPs
and tightly-coupled JSP code. My plan is to redesign the database from
scratch and then refactor the database and its attendant code bit by bit so
that in a year or so we will have completely re-engineered to database. In
other words,
1. Design a new, target schema.
2. Map the old schema to the new schema.
3. Develop a plan to convert "table clusters" from the old to the new schema.
4. Follow the plan.
For example, you may have a "company cluster" that consists of several
tables that handle company information. Convert this cluster from the old
schema to the new schema and rewrite your code base to utilize the new schema.
HTH,
Mike
design questions
So, I don't have the most design experience... but thats about to change. Iv
e
got a DB that isn't in even 1st NF and has been in Production for some time.
There are hundreds of Stored Procs already and nobody is about to start
re-writing them. So, Im thinking I need to make use of Views. In this way,
existing SP's can stay the same, new SP's can be written against the new
table structures. Im sure Im not the first one to do this, so, any gotcha's?
Anything I need to have in my mind while I do the redesign so I don't spin m
y
wheels in the wrong direction and find this approach won't work?
TIA,
ChrisRChris,
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures.
Obviously the best scenario would be a redesign to comply with 3rd NF
however it sounds like that is not going to happen. You already have an
abstraction layer to the underlying tables with stored procedures. Why do
you want to use views as well? I'm not saying that views should or should
not be used just trying to better understand your situation.
HTH
Jerry
"ChrisR" <ChrisR@.discussions.microsoft.com> wrote in message
news:6A3B81BB-2AE0-44BD-8BED-09D1F88E1398@.microsoft.com...
> So, I don't have the most design experience... but thats about to change.
> Ive
> got a DB that isn't in even 1st NF and has been in Production for some
> time.
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures. Im sure Im not the first one to do this, so, any
> gotcha's?
> Anything I need to have in my mind while I do the redesign so I don't spin
> my
> wheels in the wrong direction and find this approach won't work?
> --
> TIA,
> ChrisR|||Depends what you mean by "not in 1NF". If you intend to declare new keys and
constraints then views alone won't stop the legacy code throwing constraint
violation errors. Also, not every view may be updateable.
Triggers on INSTEAD OF views might be an option but you might find that it's
easier to rewrite the procs rather than try to accommodate every one of them
in a trigger.
David Portas
SQL Server MVP
--
"ChrisR" wrote:
> So, I don't have the most design experience... but thats about to change.
Ive
> got a DB that isn't in even 1st NF and has been in Production for some tim
e.
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures. Im sure Im not the first one to do this, so, any gotcha'
s?
> Anything I need to have in my mind while I do the redesign so I don't spin
my
> wheels in the wrong direction and find this approach won't work?
> --
> TIA,
> ChrisR|||The use of Views would be this:
Lets say we have a table called "Client":
ClientID
LName
FName
Address
Address2
City
City2
State
State2
Child1
Child2
Child3
Child4
Child5
This doesn't look too far some of the tables we have. An option would be to
Rename Client to ClientTable with only 3 columns.
ClientID
LName
FName
Another table named ClientAddress. (More than 1 address can be entered here
if needed.)
ClientID
Address
City
State
And another table called ClientChild
More than 1 child can be entered here
if needed.)
ClientID
Child
And finally, create a view named Client.
Create View Client
as
select * from ClientTable ct
inner join ClientAddress ca on ct.ClientId = ca.ClientId
inner join ClientChild cc on ct.ClientId = cc.ClientID
This is a tactic I've heard used by others, but never done it myself.
TIA,
ChrisR
"ChrisR" wrote:
> So, I don't have the most design experience... but thats about to change.
Ive
> got a DB that isn't in even 1st NF and has been in Production for some tim
e.
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures. Im sure Im not the first one to do this, so, any gotcha'
s?
> Anything I need to have in my mind while I do the redesign so I don't spin
my
> wheels in the wrong direction and find this approach won't work?
> --
> TIA,
> ChrisR|||Chris,
I am working on a major redesign at the moment. My shop also has lots of SPs
and tightly-coupled JSP code. My plan is to redesign the database from
scratch and then refactor the database and its attendant code bit by bit so
that in a year or so we will have completely re-engineered to database. In
other words,
1. Design a new, target schema.
2. Map the old schema to the new schema.
3. Develop a plan to convert "table clusters" from the old to the new schema
.
4. Follow the plan.
For example, you may have a "company cluster" that consists of several
tables that handle company information. Convert this cluster from the old
schema to the new schema and rewrite your code base to utilize the new schem
a.
HTH,
Mike
e
got a DB that isn't in even 1st NF and has been in Production for some time.
There are hundreds of Stored Procs already and nobody is about to start
re-writing them. So, Im thinking I need to make use of Views. In this way,
existing SP's can stay the same, new SP's can be written against the new
table structures. Im sure Im not the first one to do this, so, any gotcha's?
Anything I need to have in my mind while I do the redesign so I don't spin m
y
wheels in the wrong direction and find this approach won't work?
TIA,
ChrisRChris,
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures.
Obviously the best scenario would be a redesign to comply with 3rd NF
however it sounds like that is not going to happen. You already have an
abstraction layer to the underlying tables with stored procedures. Why do
you want to use views as well? I'm not saying that views should or should
not be used just trying to better understand your situation.
HTH
Jerry
"ChrisR" <ChrisR@.discussions.microsoft.com> wrote in message
news:6A3B81BB-2AE0-44BD-8BED-09D1F88E1398@.microsoft.com...
> So, I don't have the most design experience... but thats about to change.
> Ive
> got a DB that isn't in even 1st NF and has been in Production for some
> time.
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures. Im sure Im not the first one to do this, so, any
> gotcha's?
> Anything I need to have in my mind while I do the redesign so I don't spin
> my
> wheels in the wrong direction and find this approach won't work?
> --
> TIA,
> ChrisR|||Depends what you mean by "not in 1NF". If you intend to declare new keys and
constraints then views alone won't stop the legacy code throwing constraint
violation errors. Also, not every view may be updateable.
Triggers on INSTEAD OF views might be an option but you might find that it's
easier to rewrite the procs rather than try to accommodate every one of them
in a trigger.
David Portas
SQL Server MVP
--
"ChrisR" wrote:
> So, I don't have the most design experience... but thats about to change.
Ive
> got a DB that isn't in even 1st NF and has been in Production for some tim
e.
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures. Im sure Im not the first one to do this, so, any gotcha'
s?
> Anything I need to have in my mind while I do the redesign so I don't spin
my
> wheels in the wrong direction and find this approach won't work?
> --
> TIA,
> ChrisR|||The use of Views would be this:
Lets say we have a table called "Client":
ClientID
LName
FName
Address
Address2
City
City2
State
State2
Child1
Child2
Child3
Child4
Child5
This doesn't look too far some of the tables we have. An option would be to
Rename Client to ClientTable with only 3 columns.
ClientID
LName
FName
Another table named ClientAddress. (More than 1 address can be entered here
if needed.)
ClientID
Address
City
State
And another table called ClientChild
if needed.)
ClientID
Child
And finally, create a view named Client.
Create View Client
as
select * from ClientTable ct
inner join ClientAddress ca on ct.ClientId = ca.ClientId
inner join ClientChild cc on ct.ClientId = cc.ClientID
This is a tactic I've heard used by others, but never done it myself.
TIA,
ChrisR
"ChrisR" wrote:
> So, I don't have the most design experience... but thats about to change.
Ive
> got a DB that isn't in even 1st NF and has been in Production for some tim
e.
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures. Im sure Im not the first one to do this, so, any gotcha'
s?
> Anything I need to have in my mind while I do the redesign so I don't spin
my
> wheels in the wrong direction and find this approach won't work?
> --
> TIA,
> ChrisR|||Chris,
I am working on a major redesign at the moment. My shop also has lots of SPs
and tightly-coupled JSP code. My plan is to redesign the database from
scratch and then refactor the database and its attendant code bit by bit so
that in a year or so we will have completely re-engineered to database. In
other words,
1. Design a new, target schema.
2. Map the old schema to the new schema.
3. Develop a plan to convert "table clusters" from the old to the new schema
.
4. Follow the plan.
For example, you may have a "company cluster" that consists of several
tables that handle company information. Convert this cluster from the old
schema to the new schema and rewrite your code base to utilize the new schem
a.
HTH,
Mike
design questions
So, I don't have the most design experience... but thats about to change. Ive
got a DB that isn't in even 1st NF and has been in Production for some time.
There are hundreds of Stored Procs already and nobody is about to start
re-writing them. So, Im thinking I need to make use of Views. In this way,
existing SP's can stay the same, new SP's can be written against the new
table structures. Im sure Im not the first one to do this, so, any gotcha's?
Anything I need to have in my mind while I do the redesign so I don't spin my
wheels in the wrong direction and find this approach won't work?
--
TIA,
ChrisRChris,
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures.
Obviously the best scenario would be a redesign to comply with 3rd NF
however it sounds like that is not going to happen. You already have an
abstraction layer to the underlying tables with stored procedures. Why do
you want to use views as well? I'm not saying that views should or should
not be used just trying to better understand your situation.
HTH
Jerry
"ChrisR" <ChrisR@.discussions.microsoft.com> wrote in message
news:6A3B81BB-2AE0-44BD-8BED-09D1F88E1398@.microsoft.com...
> So, I don't have the most design experience... but thats about to change.
> Ive
> got a DB that isn't in even 1st NF and has been in Production for some
> time.
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures. Im sure Im not the first one to do this, so, any
> gotcha's?
> Anything I need to have in my mind while I do the redesign so I don't spin
> my
> wheels in the wrong direction and find this approach won't work?
> --
> TIA,
> ChrisR|||Depends what you mean by "not in 1NF". If you intend to declare new keys and
constraints then views alone won't stop the legacy code throwing constraint
violation errors. Also, not every view may be updateable.
Triggers on INSTEAD OF views might be an option but you might find that it's
easier to rewrite the procs rather than try to accommodate every one of them
in a trigger.
--
David Portas
SQL Server MVP
--
"ChrisR" wrote:
> So, I don't have the most design experience... but thats about to change. Ive
> got a DB that isn't in even 1st NF and has been in Production for some time.
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures. Im sure Im not the first one to do this, so, any gotcha's?
> Anything I need to have in my mind while I do the redesign so I don't spin my
> wheels in the wrong direction and find this approach won't work?
> --
> TIA,
> ChrisR|||The use of Views would be this:
Lets say we have a table called "Client":
ClientID
LName
FName
Address
Address2
City
City2
State
State2
Child1
Child2
Child3
Child4
Child5
This doesn't look too far some of the tables we have. An option would be to
Rename Client to ClientTable with only 3 columns.
ClientID
LName
FName
Another table named ClientAddress. (More than 1 address can be entered here
if needed.)
ClientID
Address
City
State
And another table called ClientChild:(More than 1 child can be entered here
if needed.)
ClientID
Child
And finally, create a view named Client.
Create View Client
as
select * from ClientTable ct
inner join ClientAddress ca on ct.ClientId = ca.ClientId
inner join ClientChild cc on ct.ClientId = cc.ClientID
This is a tactic I've heard used by others, but never done it myself.
--
TIA,
ChrisR
"ChrisR" wrote:
> So, I don't have the most design experience... but thats about to change. Ive
> got a DB that isn't in even 1st NF and has been in Production for some time.
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures. Im sure Im not the first one to do this, so, any gotcha's?
> Anything I need to have in my mind while I do the redesign so I don't spin my
> wheels in the wrong direction and find this approach won't work?
> --
> TIA,
> ChrisR|||Chris,
I am working on a major redesign at the moment. My shop also has lots of SPs
and tightly-coupled JSP code. My plan is to redesign the database from
scratch and then refactor the database and its attendant code bit by bit so
that in a year or so we will have completely re-engineered to database. In
other words,
1. Design a new, target schema.
2. Map the old schema to the new schema.
3. Develop a plan to convert "table clusters" from the old to the new schema.
4. Follow the plan.
For example, you may have a "company cluster" that consists of several
tables that handle company information. Convert this cluster from the old
schema to the new schema and rewrite your code base to utilize the new schema.
HTH,
Mike
got a DB that isn't in even 1st NF and has been in Production for some time.
There are hundreds of Stored Procs already and nobody is about to start
re-writing them. So, Im thinking I need to make use of Views. In this way,
existing SP's can stay the same, new SP's can be written against the new
table structures. Im sure Im not the first one to do this, so, any gotcha's?
Anything I need to have in my mind while I do the redesign so I don't spin my
wheels in the wrong direction and find this approach won't work?
--
TIA,
ChrisRChris,
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures.
Obviously the best scenario would be a redesign to comply with 3rd NF
however it sounds like that is not going to happen. You already have an
abstraction layer to the underlying tables with stored procedures. Why do
you want to use views as well? I'm not saying that views should or should
not be used just trying to better understand your situation.
HTH
Jerry
"ChrisR" <ChrisR@.discussions.microsoft.com> wrote in message
news:6A3B81BB-2AE0-44BD-8BED-09D1F88E1398@.microsoft.com...
> So, I don't have the most design experience... but thats about to change.
> Ive
> got a DB that isn't in even 1st NF and has been in Production for some
> time.
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures. Im sure Im not the first one to do this, so, any
> gotcha's?
> Anything I need to have in my mind while I do the redesign so I don't spin
> my
> wheels in the wrong direction and find this approach won't work?
> --
> TIA,
> ChrisR|||Depends what you mean by "not in 1NF". If you intend to declare new keys and
constraints then views alone won't stop the legacy code throwing constraint
violation errors. Also, not every view may be updateable.
Triggers on INSTEAD OF views might be an option but you might find that it's
easier to rewrite the procs rather than try to accommodate every one of them
in a trigger.
--
David Portas
SQL Server MVP
--
"ChrisR" wrote:
> So, I don't have the most design experience... but thats about to change. Ive
> got a DB that isn't in even 1st NF and has been in Production for some time.
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures. Im sure Im not the first one to do this, so, any gotcha's?
> Anything I need to have in my mind while I do the redesign so I don't spin my
> wheels in the wrong direction and find this approach won't work?
> --
> TIA,
> ChrisR|||The use of Views would be this:
Lets say we have a table called "Client":
ClientID
LName
FName
Address
Address2
City
City2
State
State2
Child1
Child2
Child3
Child4
Child5
This doesn't look too far some of the tables we have. An option would be to
Rename Client to ClientTable with only 3 columns.
ClientID
LName
FName
Another table named ClientAddress. (More than 1 address can be entered here
if needed.)
ClientID
Address
City
State
And another table called ClientChild:(More than 1 child can be entered here
if needed.)
ClientID
Child
And finally, create a view named Client.
Create View Client
as
select * from ClientTable ct
inner join ClientAddress ca on ct.ClientId = ca.ClientId
inner join ClientChild cc on ct.ClientId = cc.ClientID
This is a tactic I've heard used by others, but never done it myself.
--
TIA,
ChrisR
"ChrisR" wrote:
> So, I don't have the most design experience... but thats about to change. Ive
> got a DB that isn't in even 1st NF and has been in Production for some time.
> There are hundreds of Stored Procs already and nobody is about to start
> re-writing them. So, Im thinking I need to make use of Views. In this way,
> existing SP's can stay the same, new SP's can be written against the new
> table structures. Im sure Im not the first one to do this, so, any gotcha's?
> Anything I need to have in my mind while I do the redesign so I don't spin my
> wheels in the wrong direction and find this approach won't work?
> --
> TIA,
> ChrisR|||Chris,
I am working on a major redesign at the moment. My shop also has lots of SPs
and tightly-coupled JSP code. My plan is to redesign the database from
scratch and then refactor the database and its attendant code bit by bit so
that in a year or so we will have completely re-engineered to database. In
other words,
1. Design a new, target schema.
2. Map the old schema to the new schema.
3. Develop a plan to convert "table clusters" from the old to the new schema.
4. Follow the plan.
For example, you may have a "company cluster" that consists of several
tables that handle company information. Convert this cluster from the old
schema to the new schema and rewrite your code base to utilize the new schema.
HTH,
Mike
Subscribe to:
Posts (Atom)