Showing posts with label bol. Show all posts
Showing posts with label bol. Show all posts

Thursday, March 29, 2012

CREATE TABLE with multiple-column primary key?

Is it possible to issue the CREATE TABLE command and specify a multiple-colu
mn primary key?
If so, what is the syntax? I've checked BOL and as far as I can tell, you ma
y only select
a single column as the primary key *within the CREATE TABLE command*; ALTER
TABLE must be used
for multiple-column primary keys.
For example (this does *not* work):
CREATE TABLE #TEMPProcedures (ProcedureID int NOT NULL, ProcedureSuffix int
NOT NULL
PRIMARY KEY ProcedureID, ProcedureSuffix)
Thanks in advance --
CarlOnly a matter of a comma and a parenthesis. Below work fine:
CREATE TABLE #TEMPProcedures
(ProcedureID int NOT NULL
,ProcedureSuffix int NOT NULL
,PRIMARY KEY (ProcedureID, ProcedureSuffix))
I prefer to name all my contraints...
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Carl Imthurn" <nospam@.all.com> wrote in message news:uIvG984GGHA.1032@.TK2MSFTNGP12.phx.gbl
..
> Is it possible to issue the CREATE TABLE command and specify a multiple-co
lumn primary key?
> If so, what is the syntax? I've checked BOL and as far as I can tell, you
may only select
> a single column as the primary key *within the CREATE TABLE command*; ALTE
R TABLE must be used
> for multiple-column primary keys.
> For example (this does *not* work):
> CREATE TABLE #TEMPProcedures (ProcedureID int NOT NULL, ProcedureSuffix in
t NOT NULL
> PRIMARY KEY ProcedureID, ProcedureSuffix)
> Thanks in advance --
> Carl
>|||Thanks Tibor - that worked.
And, your comment about naming all constraints is well taken.
Carl
Tibor Karaszi wrote:

> Only a matter of a comma and a parenthesis. Below work fine:
> CREATE TABLE #TEMPProcedures (ProcedureID int NOT NULL
> ,ProcedureSuffix int NOT NULL
> ,PRIMARY KEY (ProcedureID, ProcedureSuffix))
> I prefer to name all my contraints...

Friday, February 17, 2012

Create Database With Attach in Restricted_user mode?

How can I attach a database and keep it in Restricted_User mode? I
cannot find a way to do this in BOL.
-- RBarryYoungTry attaching the db and then use "alter database" and set the option
"RESTRICTED_USER".
AMB
"RBarryYoung@.gmail.com" wrote:
> How can I attach a database and keep it in Restricted_User mode? I
> cannot find a way to do this in BOL.
> -- RBarryYoung
>|||No, this leaves a window of oppurtunity between the attach and the
"Alter Database". I need to "keep it" in Restricted mode, as it was
when I detached it, similar to the RESTRICTED_USER/DBO_ONLY keywords
for RETORE operations.
It is not supposed to be accessible by anyone until I am done making
the necessary changes to it.
Alejandro Mesa wrote:
> Try attaching the db and then use "alter database" and set the option
> "RESTRICTED_USER".
>
> AMB
>
> "RBarryYoung@.gmail.com" wrote:
> > How can I attach a database and keep it in Restricted_User mode? I
> > cannot find a way to do this in BOL.
> >
> > -- RBarryYoung
> >
> >|||<RBarryYoung@.gmail.com> wrote in message
news:1150144741.478126.196290@.f6g2000cwb.googlegroups.com...
> No, this leaves a window of oppurtunity between the attach and the
> "Alter Database". I need to "keep it" in Restricted mode, as it was
> when I detached it, similar to the RESTRICTED_USER/DBO_ONLY keywords
> for RETORE operations.
> It is not supposed to be accessible by anyone until I am done making
> the necessary changes to it.
Haven't tried this, but wrap the whole thing in a transaction?
> Alejandro Mesa wrote:
> > Try attaching the db and then use "alter database" and set the option
> > "RESTRICTED_USER".
> >
> >
> > AMB
> >
> >
> >
> > "RBarryYoung@.gmail.com" wrote:
> >
> > > How can I attach a database and keep it in Restricted_User mode? I
> > > cannot find a way to do this in BOL.
> > >
> > > -- RBarryYoung
> > >
> > >
>