Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
cathymomo
Starting Member
10 Posts |
Posted - 2009-02-25 : 15:36:41
|
| This is probably simple to most people but im brand spanking new at this so please forgive! I've two questions. Using SQL Server.1) In the same table, i've a column named ERStatus, its default value is 'PENDING'. The field is limited to one of the following values 'PENDING' 'APPROVED' 'DENIED'. nulls are not allowed. Second column in the same table is named ApprUserNo. Nulls allowed for the case 'PENDING' only. I was just wondering how to write, i have:ERStatus varchar DEFAULT "PENDING" not null check (ERStatus='PENDING' OR ERStatus='APPROVED' OR ERStatus='DENIED'),ApprUserNo integer not null check (ERStatus='APPROVED' OR ERStatus="DENIED")It's probably wrong!!2) I have a table with 3 columns, OrgNo, OrgName and OrgParentNo.OrgParentNo Refers to OrgNo; nulls allowed for the case of a parent organizational unit. I was wondering how to write the create statment for OrgParentNo.Any help appreciated |
|
|
darkdusky
Aged Yak Warrior
591 Posts |
Posted - 2009-03-03 : 09:10:03
|
| The easiest way to create a script for an existing single table is:in SQL Server Management Studio, right-click on the table, choose "Script Table As", then "CREATE To". This generates create statement automatically. You can also do this for indexes etc. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-03 : 09:14:32
|
quote: Originally posted by cathymomo This is probably simple to most people but im brand spanking new at this so please forgive! I've two questions. Using SQL Server.1) In the same table, i've a column named ERStatus, its default value is 'PENDING'. The field is limited to one of the following values 'PENDING' 'APPROVED' 'DENIED'. nulls are not allowed. Second column in the same table is named ApprUserNo. Nulls allowed for the case 'PENDING' only. I was just wondering how to write, i have:ERStatus varchar DEFAULT "PENDING" not null check (ERStatus='PENDING' OR ERStatus='APPROVED' OR ERStatus='DENIED'),ApprUserNo integer not null check (ERStatus='APPROVED' OR ERStatus="DENIED")It's probably wrong!!2) I have a table with 3 columns, OrgNo, OrgName and OrgParentNo.OrgParentNo Refers to OrgNo; nulls allowed for the case of a parent organizational unit. I was wondering how to write the create statment for OrgParentNo.Any help appreciated
1, ApprUserNo int NULL CHECK((ApprUserNo IS NULL AND ERStatus='PENDING') OR ApprUserNo IS NOT NULL)2,CREATE table tablenamehere(OrgNo int NOT NULL,OrgName varchar(100) NOT NULL,OrgParentNo int NULL) |
 |
|
|
|
|
|
|
|