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 |
|
frage2010
Starting Member
2 Posts |
Posted - 2010-01-25 : 10:32:04
|
| hello to everyone,i have a problem and hope you can help me.I would like to create a table with many constraints.At first I would like to write the column defintion and after the last one I write the constraints.My problemist that I couldn't find the right syntax for the default constraint.Here is a sample: This one works but I want the other waycreate tabel kunde (kundennr int primary key, Name varchar(20), zahlart varchar(20) default 'Bar', etc.... ); Like this way: create table kunde (kundennr int, name varchar(20), zahlart varchar(20), datum datetime, constraint kunde_kundennr_pk primary key(kundennr), constraint kunde_zahlart zahlart default 'Bar' <-- this dosen't work's. ); I hope you can help me and sorry for my english skillsfrage2010 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-25 : 10:35:40
|
| it should be zahlart varchar(20) constraint kunde_zahlart default 'Bar' |
 |
|
|
frage2010
Starting Member
2 Posts |
Posted - 2010-01-25 : 10:45:50
|
| Thank's for you fast answer,but thgis solution ist to declare the constraint with the column together.I would like to declare the constraint after all columns with the other at the end of the table code.frage2010 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-25 : 10:48:42
|
quote: Originally posted by frage2010 Thank's for you fast answer,but thgis solution ist to declare the constraint with the column together.I would like to declare the constraint after all columns with the other at the end of the table code.frage2010
then usealter table kunde add constraint kunde_zahlart default ('Bar) for zahlart |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-01-25 : 10:59:02
|
| unfortunately, can't be done the way you want -- it is incorrect syntax. either use visakh16's alter table sample, or define the constraint inline with the column definition. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
SQLJames
Starting Member
35 Posts |
Posted - 2010-01-25 : 12:40:30
|
quote: And does anyone know if England has a July 4th?
Oh yeah, and good times are had by all! Especially the Pin-the-Tail-on-the-Benjamin-Franklin |
 |
|
|
|
|
|
|
|