Showing posts with label therei. Show all posts
Showing posts with label therei. Show all posts

Tuesday, March 27, 2012

Gerating sql script with default

Hello there
I have database that i add on there default
On the nornal script the tables are run first. Now the tables cannot be
created because they are based on the default
What i need to do to generate the script from now
Or how can i cancel the default?
need assistance imergancyI assume you are talking about a default object. You can create default
objects with:
CREATE DEFAULT <default name> AS <expression>
If you put this in your script to create the default before you create the
tables, thing should work fine.
Note that defaults created in this way are a backward compatibility feature,
and to ensure that your code will work with future versions of SQL Server,
you should declare DEFAULTs as column constraints.
Jacco Schalkwijk
SQL Server MVP
"Roy Goldhammer" <roygoldh@.hotmail.com> wrote in message
news:%23Tm4r8hKFHA.436@.TK2MSFTNGP09.phx.gbl...
> Hello there
> I have database that i add on there default
> On the nornal script the tables are run first. Now the tables cannot be
> created because they are based on the default
> What i need to do to generate the script from now
> Or how can i cancel the default?
> need assistance imergancy
>
>|||Can't you just edit the script and put the DEFAULTs at the beginning?
CREATE DEFAULT is virtually obsolete so I would go with the
recommendation in Books Online: avoid it and use Default Constraints
instead.
David Portas
SQL Server MVP
--|||Thankes
So how can i get rid of it now?
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1110974952.692560.119730@.f14g2000cwb.googlegroups.com...
> Can't you just edit the script and put the DEFAULTs at the beginning?
> CREATE DEFAULT is virtually obsolete so I would go with the
> recommendation in Books Online: avoid it and use Default Constraints
> instead.
> --
> David Portas
> SQL Server MVP
> --
>|||To get rid of the error message just put in the CREATE DEFAULT
statements. To get rid of the defaults altogether you'll have to
replace all references to sp_bindefault with an ALTER TABLE... ADD
CONSTRAINT statement instead. For example:
EXEC sp_bindefault 'default_name', 'table_name.column_name'
should become:
ALTER TABLE table_name
ADD CONSTRAINT df_constraint_name
DEFAULT (<default value> ) FOR column_name
David Portas
SQL Server MVP
--|||Thankes David
I found out another way to do this?
sp_unbinddefault 'table_name.field_name'
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1110977180.528780.196840@.f14g2000cwb.googlegroups.com...
> To get rid of the error message just put in the CREATE DEFAULT
> statements. To get rid of the defaults altogether you'll have to
> replace all references to sp_bindefault with an ALTER TABLE... ADD
> CONSTRAINT statement instead. For example:
> EXEC sp_bindefault 'default_name', 'table_name.column_name'
> should become:
> ALTER TABLE table_name
> ADD CONSTRAINT df_constraint_name
> DEFAULT (<default value> ) FOR column_name
> --
> David Portas
> SQL Server MVP
> --
>|||Be aware that sp_unbindefault will disable the functionality of the
default. Inserts that don't specify explicit values for a column will
therefore atempt to populate the column with NULL. The insert will fail
if the column is not nullable.
David Portas
SQL Server MVP
--

Friday, March 23, 2012

Generating SQL Script

Hello there
I have huge database on sql server. The database probide tables, views,
store procedures and functions
Some of the views or the store procedures are depend on the functions, store
presedures are depend on the views.
When i update the version I generate SQL Script and run it on my client
The script first of all destroy objects on the client and establish the new
schema. The sql script firs create tables, views, store procedures and at
finaly functions.
Because some of the views or the store procedures are using the functions
they can't be created.
What i need to do to create first the functions?
and if on the future i will create functions that using functions. Is there
a "smart" script that first of all create the objects without any
dependencies and after that create wnat under them?
any help would be usefulI have the same problem with some scripts I generate. Here's the solutions
I came up with:
1) manually re-arrange the script so that objects that need to be created
first are created first, or
2) generate multiple scripts (generate one that just creates functions, one
that just creates views, etc.)
I prefer the second method myself, since it's less work, especially for very
large scripts.
Thx
"Roy Goldhammer" <roygoldh@.hotmail.com> wrote in message
news:%23blV03ZHFHA.400@.TK2MSFTNGP14.phx.gbl...
> Hello there
> I have huge database on sql server. The database probide tables, views,
> store procedures and functions
> Some of the views or the store procedures are depend on the functions,
> store
> presedures are depend on the views.
> When i update the version I generate SQL Script and run it on my client
> The script first of all destroy objects on the client and establish the
> new
> schema. The sql script firs create tables, views, store procedures and at
> finaly functions.
> Because some of the views or the store procedures are using the functions
> they can't be created.
> What i need to do to create first the functions?
> and if on the future i will create functions that using functions. Is
> there
> a "smart" script that first of all create the objects without any
> dependencies and after that create wnat under them?
> any help would be useful
>

Friday, February 24, 2012

generate attributelist from tables

hi there!
I've been working on a project in ASP.NET and SQLserver 2000.
Since this is actually something for school, I must give a report on my work done here.
What I want to do is make an attributelist of all the tables that are in a database, or one at the time would already be a great help!
So for each table I would need in text format all its column names, types en 'allow null' property, but I just can't find out how or with what to do this.

thanks for your help!
Tombaselect * from INFORMATION_SCHEMA.COLUMNS