Friday, March 23, 2012
how to make a 'my reports' folder
I am having some trouble getting the 'My Reports' folder to appear for all
users. The docs just say that as long as the user exists as a windows user
and the 'My Reports' option is ticked in 'Site Settings', ReportServer
should just create a 'My Reports' folder the first time a user logs onto the
ReportServer. But this is not working for all users. About half of the
users have the 'My Reports' folder created. So I need to know how to create
them manually, or at least some workaround to get each user a 'My Reports'
folder!
I don't see any difference between the user accts (other than the names).
Thanks,
LanceLance,
Have you checked to ensure all users are are included in the "My Reports"
role - or in some custom role that includes the required permissions.
Regards,
Rob Labbé, MCP, MCAD, MCSD, MCT
Lead Architect/Trainer
Fidelis
Blog: http://spaces.msn.com/members/roblabbe
"Lance" <lance@.[nospam]keayweb.com> wrote in message
news:11849vnplj1n02@.corp.supernews.com...
> Hi,
> I am having some trouble getting the 'My Reports' folder to appear for all
> users. The docs just say that as long as the user exists as a windows
> user
> and the 'My Reports' option is ticked in 'Site Settings', ReportServer
> should just create a 'My Reports' folder the first time a user logs onto
> the
> ReportServer. But this is not working for all users. About half of the
> users have the 'My Reports' folder created. So I need to know how to
> create
> them manually, or at least some workaround to get each user a 'My Reports'
> folder!
> I don't see any difference between the user accts (other than the names).
> Thanks,
> Lance
>|||Hi,
Thanks for the reply, but I am a bit confused about it! Maybe if I explain
a bit more about the setup: The ReportServer is set up with no common
reports. Each user can *only* view the reports in their own 'My Reports'
folder. As such each user *must* have a 'My Reports' folder! (obviously)
Here is how the server is set up:
* There are the standard 'Item-level' roles and an additional one,
'Viewer' - which is a limited acct, that just allows the user to 'view
folders' and 'view reports'. None of the non-admin users can create
reports.
* The 'System Roles' are the standard 'System Administrator' and 'System
User' - the 'System User' has the 'View report server properties' and 'View
shared schedules' tasks.
* The 'Enable My Reports to support user-owned folders for publishing and
running personalized reports.' checkbox is checked in the 'Reporst Server'
'Site Settings'. The 'Choose the role to apply to each user's My Reports
folder' dropdown is 'Viewer'
To set up for a new user:
* Each new user is added to the 'Users' group on the server (windows 2000
server).
* The user logs in, and a 'My Reports' folder should be created.
But mostly, a 'My Reports' folder is *not* created. Or perhaps just not
shown. I don't know how to check whether there is a 'My Reports' folder for
the user - I am thinking that there is a value in the DB somewhere that
tells me...
I was experimenting with a dozen new users, and the docs say that as soon as
a windows user logs in, a 'My Reports' folder should be created. I tried
both creating a 'System Role' for the user and *not* creating a system role,
but the creation of the 'My Reports' folder seems to occur randomly. I say
*seem*, as I am sure that I am missing a step or something, as I confess
that I find the role assignment somewhat confusing. But I'm new, and I am
sure I'll get used to it...
In response to your kindly answer:
So, from my limited understanding, the 'My Reports' role is an 'item-level'
role; I can only seem to assign to this at the report level (ie an 'item')
*not* to a user. But if the 'My Reports' folder is not being created, I
can't assign this 'tiem-level' role to it!
In short: I am still stuck with some users having a 'My Reports' folder and
most users *not* having one!
Thanks,
Lance
> Lance,
> Have you checked to ensure all users are are included in the "My Reports"
> role - or in some custom role that includes the required permissions.
> Regards,
>
> --
> Rob Labbé, MCP, MCAD, MCSD, MCT
> Lead Architect/Trainer
> Fidelis
> Blog: http://spaces.msn.com/members/roblabbe
> "Lance" <lance@.[nospam]keayweb.com> wrote in message
> news:11849vnplj1n02@.corp.supernews.com...
> > Hi,
> > I am having some trouble getting the 'My Reports' folder to appear for
all
> > users. The docs just say that as long as the user exists as a windows
> > user
> > and the 'My Reports' option is ticked in 'Site Settings', ReportServer
> > should just create a 'My Reports' folder the first time a user logs onto
> > the
> > ReportServer. But this is not working for all users. About half of the
> > users have the 'My Reports' folder created. So I need to know how to
> > create
> > them manually, or at least some workaround to get each user a 'My
Reports'
> > folder!
> >
> > I don't see any difference between the user accts (other than the
names).
> >
> > Thanks,
> > Lance
> >
> >
>|||Hi,
I was just nosing around the DB, and I noticed that all the users are in the
'users' table, but the user accounts don't appear in the 'PolicyUserRole'
table, and hence there are not any policies for them.
I don't know if this helps any or just confuses...
And there aren't any application events in the log on the server, either.
"Lance" <lance@.[nospam]keayweb.com> wrote in message
news:11869vtmjhs8i08@.corp.supernews.com...
> Hi,
> Thanks for the reply, but I am a bit confused about it! Maybe if I
explain
> a bit more about the setup: The ReportServer is set up with no common
> reports. Each user can *only* view the reports in their own 'My Reports'
> folder. As such each user *must* have a 'My Reports' folder! (obviously)
> Here is how the server is set up:
> * There are the standard 'Item-level' roles and an additional one,
> 'Viewer' - which is a limited acct, that just allows the user to 'view
> folders' and 'view reports'. None of the non-admin users can create
> reports.
> * The 'System Roles' are the standard 'System Administrator' and 'System
> User' - the 'System User' has the 'View report server properties' and
'View
> shared schedules' tasks.
> * The 'Enable My Reports to support user-owned folders for publishing and
> running personalized reports.' checkbox is checked in the 'Reporst Server'
> 'Site Settings'. The 'Choose the role to apply to each user's My Reports
> folder' dropdown is 'Viewer'
> To set up for a new user:
> * Each new user is added to the 'Users' group on the server (windows 2000
> server).
> * The user logs in, and a 'My Reports' folder should be created.
> But mostly, a 'My Reports' folder is *not* created. Or perhaps just not
> shown. I don't know how to check whether there is a 'My Reports' folder
for
> the user - I am thinking that there is a value in the DB somewhere that
> tells me...
> I was experimenting with a dozen new users, and the docs say that as soon
as
> a windows user logs in, a 'My Reports' folder should be created. I tried
> both creating a 'System Role' for the user and *not* creating a system
role,
> but the creation of the 'My Reports' folder seems to occur randomly. I
say
> *seem*, as I am sure that I am missing a step or something, as I confess
> that I find the role assignment somewhat confusing. But I'm new, and I am
> sure I'll get used to it...
>
> In response to your kindly answer:
> So, from my limited understanding, the 'My Reports' role is an
'item-level'
> role; I can only seem to assign to this at the report level (ie an 'item')
> *not* to a user. But if the 'My Reports' folder is not being created, I
> can't assign this 'tiem-level' role to it!
>
> In short: I am still stuck with some users having a 'My Reports' folder
and
> most users *not* having one!
> Thanks,
> Lance
>
>
> > Lance,
> >
> > Have you checked to ensure all users are are included in the "My
Reports"
> > role - or in some custom role that includes the required permissions.
> >
> > Regards,
> >
> >
> > --
> > Rob Labbé, MCP, MCAD, MCSD, MCT
> > Lead Architect/Trainer
> > Fidelis
> >
> > Blog: http://spaces.msn.com/members/roblabbe
> >
> > "Lance" <lance@.[nospam]keayweb.com> wrote in message
> > news:11849vnplj1n02@.corp.supernews.com...
> > > Hi,
> > > I am having some trouble getting the 'My Reports' folder to appear for
> all
> > > users. The docs just say that as long as the user exists as a windows
> > > user
> > > and the 'My Reports' option is ticked in 'Site Settings', ReportServer
> > > should just create a 'My Reports' folder the first time a user logs
onto
> > > the
> > > ReportServer. But this is not working for all users. About half of
the
> > > users have the 'My Reports' folder created. So I need to know how to
> > > create
> > > them manually, or at least some workaround to get each user a 'My
> Reports'
> > > folder!
> > >
> > > I don't see any difference between the user accts (other than the
> names).
> > >
> > > Thanks,
> > > Lance
> > >
> > >
> >
> >
>sql
Friday, March 9, 2012
How to link a login to a database user
SQL Server login name USER1. When I double-click on the login name, in the
Database Access page, I find that USER1 is permitted to access INVENTORY.
However, there is no linkage between the login USER1 and database owner
USER1. The "User" cell at the right of the INVENTORY database is blank in
the Database Access page. However when I try to enter USER1 into the cell, I
get an error message telling me the user USER1 already exists in INVENTORY.
However can I link the login name to the database user name?
TIA
KMTake a look at sp_change_users_login in BooksOnLine.
Andrew J. Kelly SQL MVP
"Krygim" <krygim@.hotmail.com> wrote in message
news:uT89uyOOEHA.4036@.TK2MSFTNGP12.phx.gbl...
> USER1 is the db_owner of the database INVENTORY. There exists an identical
> SQL Server login name USER1. When I double-click on the login name, in the
> Database Access page, I find that USER1 is permitted to access INVENTORY.
> However, there is no linkage between the login USER1 and database owner
> USER1. The "User" cell at the right of the INVENTORY database is blank in
> the Database Access page. However when I try to enter USER1 into the cell,
I
> get an error message telling me the user USER1 already exists in
INVENTORY.
> However can I link the login name to the database user name?
> TIA
> KM
>|||Hi,
Did you restore the database Inventory recently. This would have caused the
link break between syslogins table in master and
sysusers table in Inventory database. The link can be brought again by
executing the below statements in query analyzer:-
USE Inventory
go
sp_change_users_login 'Update_One', 'user1', 'user1'
Tahnks
Hari
MCDBA
"Krygim" <krygim@.hotmail.com> wrote in message
news:uT89uyOOEHA.4036@.TK2MSFTNGP12.phx.gbl...
> USER1 is the db_owner of the database INVENTORY. There exists an identical
> SQL Server login name USER1. When I double-click on the login name, in the
> Database Access page, I find that USER1 is permitted to access INVENTORY.
> However, there is no linkage between the login USER1 and database owner
> USER1. The "User" cell at the right of the INVENTORY database is blank in
> the Database Access page. However when I try to enter USER1 into the cell,
I
> get an error message telling me the user USER1 already exists in
INVENTORY.
> However can I link the login name to the database user name?
> TIA
> KM
>|||Exactly! I have just restored the database.
Thank you and Andrew for the solution.
KM
"Hari Prasad" <hari_prasad_k@.hotmail.com> wrote in message
news:elJZo8OOEHA.2976@.TK2MSFTNGP10.phx.gbl...
> Hi,
> Did you restore the database Inventory recently. This would have caused
the
> link break between syslogins table in master and
> sysusers table in Inventory database. The link can be brought again by
> executing the below statements in query analyzer:-
> USE Inventory
> go
> sp_change_users_login 'Update_One', 'user1', 'user1'
> Tahnks
> Hari
> MCDBA
>
> "Krygim" <krygim@.hotmail.com> wrote in message
> news:uT89uyOOEHA.4036@.TK2MSFTNGP12.phx.gbl...
identical[vbcol=seagreen]
the[vbcol=seagreen]
INVENTORY.[vbcol=seagreen]
in[vbcol=seagreen]
cell,[vbcol=seagreen]
> I
> INVENTORY.
>
Sunday, February 19, 2012
How to know if a record exists
I have a TextBox and an Insert Button, it works like this:
protected void Button1_Click(object sender, EventArgs e)
{
String strConn=SqlDataSource1.ConnectionString;
SqlCommand cmd =new SqlCommand("INSERT INTO My_Table_1 (Column_1) VALUES ("+TextBox1.Text+")",new SqlConnection(strConn));cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
}
But,what code i must write for checking, if the value i am trying to insert already exists ??
I mean something like this:
if (TextBox1.Text does not Exists on any Record in My_Table_1) then
Insert it
else
Show Message : "Already exists a record with this value"
Thank you SO MUCH, guys,
Carlos.you can execute "select count(*) from My_Table_1 whereColumn_1='"+TextBox1.Text+"'" before insert and get value of the firstcolumn, then use if to determine whether it is bigger than 0|||
you could write a stored procedure and pass the insert parameters to it. In the stored proc you could do a check as follows:
IF NOT EXISTS(SELECT * FROM <table> WHERE <Condition>)
BEGIN
INSERT INTO <table> (<columns>) VALUES (<Values>)
END
If you want to return an appropriate message back to the front end you could include a return value as an OUTPUT parameter and return a code appropriately.
|||Hello Tony and Ndinakar:thanks for the replies ;)
I will try first Tony's method...
BUT, how can i get the value of the first column ?
Please, can you write some code? i am REALLY new on this, and i can't find the answer :(
Thank you so much,
Carlos.|||code sample for you:)
//open connection
SqlConnection m_conn=new SqlConnection(ConnectionString);
m_conn.Open();
//run sql
sqlstring="select count(*) from My_Table_1 whereColumn_1='"+TextBox1.Text+"'" ";
SqlCommand sqlcmd=new SqlCommand(sqlstring,m_Conn);
SqlDataReader sdr=sqlcmd.ExecuteReader();
sdr.Read();
int rowcount=(int)sdr[0]; //here, you get what you need!
sdr.Close();
//determine whether record exist
if(rowcount==0)
{
//insert a new record
}
//close you connection
m_conn.Close();|||With all due respect... The second solution will give you better performance. It is essentiall the same as the first, except the exists contraint tells the query to stop executing after it finds a single match, whereas the count(*) method continues to aggregate the entire selection.|||Yes, you will be making 2 trips to insert a record which is unnecessary.|||Thank you guys for all your replies.
Tony, your code works 100% for what i am looking for, thank you ;)
In a few days i will study stored procedures, and i will try the second solution, and i will post my results here.
Thanks again,
Carlos.
how to know if a DEFAULT exists or not
how i can now if a DEFAULT exists for a given row in a table.
for exemple:
ALTER TABLE MyTable ADD
CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
This adds the Default NEWID() to the row MyRow in the table MyTable.
But when i run this query a second time, i get a warning ("Column already
has a DEFAULT bound to it.") that it already exists. So I would like my
query check first if it is there or not, and if not add the Default.
How do i do this? I can't find anything on google :-/
Thanks,
Pieter
IF NOT EXISTS(SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE
Constraint_Name like 'DF_MyTable_MyRow'
ALTER TABLE MyTable ADD
CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
"DraguVaso" <pietercoucke@.hotmail.com> schrieb im Newsbeitrag
news:Oct$xeKVFHA.2520@.TK2MSFTNGP09.phx.gbl...
> For a script that should update some table-definitions, I would like to
> know
> how i can now if a DEFAULT exists for a given row in a table.
> for exemple:
IF NOT EXISTS(SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE
Constraint_Name like 'DF_MyTable_MyRow'
ALTER TABLE MyTable ADD
CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
> This adds the Default NEWID() to the row MyRow in the table MyTable.
> But when i run this query a second time, i get a warning ("Column already
> has a DEFAULT bound to it.") that it already exists. So I would like my
> query check first if it is there or not, and if not add the Default.
> How do i do this? I can't find anything on google :-/
> Thanks,
> Pieter
>
|||hi,
Unfortunately it works only for CHECK, UNIQUE, PRIMARY KEY, or FOREIGN KEY,
and not for DEFAULT :-(
any other idea?
"Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote in
message news:ew4NznKVFHA.3540@.TK2MSFTNGP15.phx.gbl...[vbcol=seagreen]
> IF NOT EXISTS(SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE
> Constraint_Name like 'DF_MyTable_MyRow'
> ALTER TABLE MyTable ADD
> CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
>
> "DraguVaso" <pietercoucke@.hotmail.com> schrieb im Newsbeitrag
> news:Oct$xeKVFHA.2520@.TK2MSFTNGP09.phx.gbl...
> IF NOT EXISTS(SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE
> Constraint_Name like 'DF_MyTable_MyRow'
> ALTER TABLE MyTable ADD
> CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
already
>
|||create table t(c1 int default 1)
GO
select *
from sysobjects so inner join sysconstraints sc on so.id = sc.id
where so.id = object_id('t')
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"DraguVaso" <pietercoucke@.hotmail.com> wrote in message
news:Oct$xeKVFHA.2520@.TK2MSFTNGP09.phx.gbl...
> For a script that should update some table-definitions, I would like to know
> how i can now if a DEFAULT exists for a given row in a table.
> for exemple:
> ALTER TABLE MyTable ADD
> CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
> This adds the Default NEWID() to the row MyRow in the table MyTable.
> But when i run this query a second time, i get a warning ("Column already
> has a DEFAULT bound to it.") that it already exists. So I would like my
> query check first if it is there or not, and if not add the Default.
> How do i do this? I can't find anything on google :-/
> Thanks,
> Pieter
>
|||Your are right, you can try that from Dejan Serka:
select
db_name() as CONSTRAINT_CATALOG
,user_name(c_obj.uid) as CONSTRAINT_SCHEMA
,c_obj.name as CONSTRAINT_NAME
,com.text as DEFAULT_CLAUSE
from
sysobjects c_obj
,syscomments com
where
c_obj.uid = user_id()
and c_obj.id = com.id
and c_obj.xtype = 'D'
Found under
http://sql.reproms.si/data/podatki/d...st raints.sql
to change to standard beaviour of the Information Views,
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
"DraguVaso" <pietercoucke@.hotmail.com> schrieb im Newsbeitrag
news:OluNH3KVFHA.1452@.TK2MSFTNGP14.phx.gbl...
> hi,
> Unfortunately it works only for CHECK, UNIQUE, PRIMARY KEY, or FOREIGN
> KEY,
> and not for DEFAULT :-(
> any other idea?
> "Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote
> in
> message news:ew4NznKVFHA.3540@.TK2MSFTNGP15.phx.gbl...
> already
>
|||Try,
declare @.sql nvarchar(4000)
declare @.cnstname sysname
select
@.cnstname = [name]
from
sysobjects as so
where
xtype = 'D'
and parent_obj = object_id('dbo.t')
and col_name(parent_obj, info) = 'colB'
if @.cnstname is not null
print @.cnstname
else
print 'no default for column [colB] in table [t].'
go
AMB
"DraguVaso" wrote:
> For a script that should update some table-definitions, I would like to know
> how i can now if a DEFAULT exists for a given row in a table.
> for exemple:
> ALTER TABLE MyTable ADD
> CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
> This adds the Default NEWID() to the row MyRow in the table MyTable.
> But when i run this query a second time, i get a warning ("Column already
> has a DEFAULT bound to it.") that it already exists. So I would like my
> query check first if it is there or not, and if not add the Default.
> How do i do this? I can't find anything on google :-/
> Thanks,
> Pieter
>
>
|||Ok thanks! Works fine!
The solution of Alejandro works fine too! thanks a lot guys!
"Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote in
message news:%23BWTRFLVFHA.3152@.TK2MSFTNGP12.phx.gbl...
> Your are right, you can try that from Dejan Serka:
> select
> db_name() as CONSTRAINT_CATALOG
> ,user_name(c_obj.uid) as CONSTRAINT_SCHEMA
> ,c_obj.name as CONSTRAINT_NAME
> ,com.text as DEFAULT_CLAUSE
> from
> sysobjects c_obj
> ,syscomments com
> where
> c_obj.uid = user_id()
> and c_obj.id = com.id
> and c_obj.xtype = 'D'
> Found under
>
http://sql.reproms.si/data/podatki/d...st raints.sql[vbcol=seagreen]
> to change to standard beaviour of the Information Views,
>
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
> "DraguVaso" <pietercoucke@.hotmail.com> schrieb im Newsbeitrag
> news:OluNH3KVFHA.1452@.TK2MSFTNGP14.phx.gbl...
to[vbcol=seagreen]
my
>
how to know if a DEFAULT exists or not
how i can now if a DEFAULT exists for a given row in a table.
for exemple:
ALTER TABLE MyTable ADD
CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
This adds the Default NEWID() to the row MyRow in the table MyTable.
But when i run this query a second time, i get a warning ("Column already
has a DEFAULT bound to it.") that it already exists. So I would like my
query check first if it is there or not, and if not add the Default.
How do i do this? I can't find anything on google :-/
Thanks,
PieterIF NOT EXISTS(SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE
Constraint_Name like 'DF_MyTable_MyRow'
ALTER TABLE MyTable ADD
CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"DraguVaso" <pietercoucke@.hotmail.com> schrieb im Newsbeitrag
news:Oct$xeKVFHA.2520@.TK2MSFTNGP09.phx.gbl...
> For a script that should update some table-definitions, I would like to
> know
> how i can now if a DEFAULT exists for a given row in a table.
> for exemple:
IF NOT EXISTS(SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE
Constraint_Name like 'DF_MyTable_MyRow'
ALTER TABLE MyTable ADD
CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
> This adds the Default NEWID() to the row MyRow in the table MyTable.
> But when i run this query a second time, i get a warning ("Column already
> has a DEFAULT bound to it.") that it already exists. So I would like my
> query check first if it is there or not, and if not add the Default.
> How do i do this? I can't find anything on google :-/
> Thanks,
> Pieter
>|||hi,
Unfortunately it works only for CHECK, UNIQUE, PRIMARY KEY, or FOREIGN KEY,
and not for DEFAULT :-(
any other idea?
"Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote in
message news:ew4NznKVFHA.3540@.TK2MSFTNGP15.phx.gbl...
> IF NOT EXISTS(SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE
> Constraint_Name like 'DF_MyTable_MyRow'
> ALTER TABLE MyTable ADD
> CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
>
> "DraguVaso" <pietercoucke@.hotmail.com> schrieb im Newsbeitrag
> news:Oct$xeKVFHA.2520@.TK2MSFTNGP09.phx.gbl...
> IF NOT EXISTS(SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE
> Constraint_Name like 'DF_MyTable_MyRow'
> ALTER TABLE MyTable ADD
> CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
already[vbcol=seagreen]
>|||create table t(c1 int default 1)
GO
select *
from sysobjects so inner join sysconstraints sc on so.id = sc.id
where so.id = object_id('t')
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"DraguVaso" <pietercoucke@.hotmail.com> wrote in message
news:Oct$xeKVFHA.2520@.TK2MSFTNGP09.phx.gbl...
> For a script that should update some table-definitions, I would like to kn
ow
> how i can now if a DEFAULT exists for a given row in a table.
> for exemple:
> ALTER TABLE MyTable ADD
> CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
> This adds the Default NEWID() to the row MyRow in the table MyTable.
> But when i run this query a second time, i get a warning ("Column already
> has a DEFAULT bound to it.") that it already exists. So I would like my
> query check first if it is there or not, and if not add the Default.
> How do i do this? I can't find anything on google :-/
> Thanks,
> Pieter
>|||Your are right, you can try that from Dejan Serka:
select
db_name() as CONSTRAINT_CATALOG
,user_name(c_obj.uid) as CONSTRAINT_SCHEMA
,c_obj.name as CONSTRAINT_NAME
,com.text as DEFAULT_CLAUSE
from
sysobjects c_obj
,syscomments com
where
c_obj.uid = user_id()
and c_obj.id = com.id
and c_obj.xtype = 'D'
Found under
http://sql.reproms.si/data/podatki/...Constraints.sql
to change to standard beaviour of the Information Views,
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"DraguVaso" <pietercoucke@.hotmail.com> schrieb im Newsbeitrag
news:OluNH3KVFHA.1452@.TK2MSFTNGP14.phx.gbl...
> hi,
> Unfortunately it works only for CHECK, UNIQUE, PRIMARY KEY, or FOREIGN
> KEY,
> and not for DEFAULT :-(
> any other idea?
> "Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote
> in
> message news:ew4NznKVFHA.3540@.TK2MSFTNGP15.phx.gbl...
> already
>|||Try,
declare @.sql nvarchar(4000)
declare @.cnstname sysname
select
@.cnstname = [name]
from
sysobjects as so
where
xtype = 'D'
and parent_obj = object_id('dbo.t')
and col_name(parent_obj, info) = 'colB'
if @.cnstname is not null
print @.cnstname
else
print 'no default for column [colB] in table [t].'
go
AMB
"DraguVaso" wrote:
> For a script that should update some table-definitions, I would like to kn
ow
> how i can now if a DEFAULT exists for a given row in a table.
> for exemple:
> ALTER TABLE MyTable ADD
> CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
> This adds the Default NEWID() to the row MyRow in the table MyTable.
> But when i run this query a second time, i get a warning ("Column already
> has a DEFAULT bound to it.") that it already exists. So I would like my
> query check first if it is there or not, and if not add the Default.
> How do i do this? I can't find anything on google :-/
> Thanks,
> Pieter
>
>|||Ok thanks! Works fine!
The solution of Alejandro works fine too! thanks a lot guys!
"Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote in
message news:%23BWTRFLVFHA.3152@.TK2MSFTNGP12.phx.gbl...
> Your are right, you can try that from Dejan Serka:
> select
> db_name() as CONSTRAINT_CATALOG
> ,user_name(c_obj.uid) as CONSTRAINT_SCHEMA
> ,c_obj.name as CONSTRAINT_NAME
> ,com.text as DEFAULT_CLAUSE
> from
> sysobjects c_obj
> ,syscomments com
> where
> c_obj.uid = user_id()
> and c_obj.id = com.id
> and c_obj.xtype = 'D'
> Found under
>
http://sql.reproms.si/data/podatki/...nts.
sql
> to change to standard beaviour of the Information Views,
>
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
> "DraguVaso" <pietercoucke@.hotmail.com> schrieb im Newsbeitrag
> news:OluNH3KVFHA.1452@.TK2MSFTNGP14.phx.gbl...
to[vbcol=seagreen]
my[vbcol=seagreen]
>
how to know if a DEFAULT exists or not
how i can now if a DEFAULT exists for a given row in a table.
for exemple:
ALTER TABLE MyTable ADD
CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
This adds the Default NEWID() to the row MyRow in the table MyTable.
But when i run this query a second time, i get a warning ("Column already
has a DEFAULT bound to it.") that it already exists. So I would like my
query check first if it is there or not, and if not add the Default.
How do i do this? I can't find anything on google :-/
Thanks,
PieterIF NOT EXISTS(SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE
Constraint_Name like 'DF_MyTable_MyRow'
ALTER TABLE MyTable ADD
CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
HTH, Jens Suessmeyer.
--
http://www.sqlserver2005.de
--
"DraguVaso" <pietercoucke@.hotmail.com> schrieb im Newsbeitrag
news:Oct$xeKVFHA.2520@.TK2MSFTNGP09.phx.gbl...
> For a script that should update some table-definitions, I would like to
> know
> how i can now if a DEFAULT exists for a given row in a table.
> for exemple:
IF NOT EXISTS(SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE
Constraint_Name like 'DF_MyTable_MyRow'
ALTER TABLE MyTable ADD
CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
> This adds the Default NEWID() to the row MyRow in the table MyTable.
> But when i run this query a second time, i get a warning ("Column already
> has a DEFAULT bound to it.") that it already exists. So I would like my
> query check first if it is there or not, and if not add the Default.
> How do i do this? I can't find anything on google :-/
> Thanks,
> Pieter
>|||hi,
Unfortunately it works only for CHECK, UNIQUE, PRIMARY KEY, or FOREIGN KEY,
and not for DEFAULT :-(
any other idea?
"Jens Süßmeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote in
message news:ew4NznKVFHA.3540@.TK2MSFTNGP15.phx.gbl...
> IF NOT EXISTS(SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE
> Constraint_Name like 'DF_MyTable_MyRow'
> ALTER TABLE MyTable ADD
> CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
>
> "DraguVaso" <pietercoucke@.hotmail.com> schrieb im Newsbeitrag
> news:Oct$xeKVFHA.2520@.TK2MSFTNGP09.phx.gbl...
> > For a script that should update some table-definitions, I would like to
> > know
> > how i can now if a DEFAULT exists for a given row in a table.
> >
> > for exemple:
> IF NOT EXISTS(SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE
> Constraint_Name like 'DF_MyTable_MyRow'
> ALTER TABLE MyTable ADD
> CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
> >
> > This adds the Default NEWID() to the row MyRow in the table MyTable.
> > But when i run this query a second time, i get a warning ("Column
already
> > has a DEFAULT bound to it.") that it already exists. So I would like my
> > query check first if it is there or not, and if not add the Default.
> >
> > How do i do this? I can't find anything on google :-/
> >
> > Thanks,
> >
> > Pieter
> >
> >
>|||create table t(c1 int default 1)
GO
select *
from sysobjects so inner join sysconstraints sc on so.id = sc.id
where so.id = object_id('t')
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"DraguVaso" <pietercoucke@.hotmail.com> wrote in message
news:Oct$xeKVFHA.2520@.TK2MSFTNGP09.phx.gbl...
> For a script that should update some table-definitions, I would like to know
> how i can now if a DEFAULT exists for a given row in a table.
> for exemple:
> ALTER TABLE MyTable ADD
> CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
> This adds the Default NEWID() to the row MyRow in the table MyTable.
> But when i run this query a second time, i get a warning ("Column already
> has a DEFAULT bound to it.") that it already exists. So I would like my
> query check first if it is there or not, and if not add the Default.
> How do i do this? I can't find anything on google :-/
> Thanks,
> Pieter
>|||Your are right, you can try that from Dejan Serka:
select
db_name() as CONSTRAINT_CATALOG
,user_name(c_obj.uid) as CONSTRAINT_SCHEMA
,c_obj.name as CONSTRAINT_NAME
,com.text as DEFAULT_CLAUSE
from
sysobjects c_obj
,syscomments com
where
c_obj.uid = user_id()
and c_obj.id = com.id
and c_obj.xtype = 'D'
Found under
http://sql.reproms.si/data/podatki/dejan/INFORMATION_SCHEMA%20Views%20for%20Default%20Constraints.sql
to change to standard beaviour of the Information Views,
HTH, Jens Suessmeyer.
--
http://www.sqlserver2005.de
--
"DraguVaso" <pietercoucke@.hotmail.com> schrieb im Newsbeitrag
news:OluNH3KVFHA.1452@.TK2MSFTNGP14.phx.gbl...
> hi,
> Unfortunately it works only for CHECK, UNIQUE, PRIMARY KEY, or FOREIGN
> KEY,
> and not for DEFAULT :-(
> any other idea?
> "Jens Süßmeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote
> in
> message news:ew4NznKVFHA.3540@.TK2MSFTNGP15.phx.gbl...
>> IF NOT EXISTS(SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE
>> Constraint_Name like 'DF_MyTable_MyRow'
>> ALTER TABLE MyTable ADD
>> CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
>> HTH, Jens Suessmeyer.
>> --
>> http://www.sqlserver2005.de
>> --
>>
>> "DraguVaso" <pietercoucke@.hotmail.com> schrieb im Newsbeitrag
>> news:Oct$xeKVFHA.2520@.TK2MSFTNGP09.phx.gbl...
>> > For a script that should update some table-definitions, I would like to
>> > know
>> > how i can now if a DEFAULT exists for a given row in a table.
>> >
>> > for exemple:
>> IF NOT EXISTS(SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE
>> Constraint_Name like 'DF_MyTable_MyRow'
>> ALTER TABLE MyTable ADD
>> CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
>> >
>> > This adds the Default NEWID() to the row MyRow in the table MyTable.
>> > But when i run this query a second time, i get a warning ("Column
> already
>> > has a DEFAULT bound to it.") that it already exists. So I would like my
>> > query check first if it is there or not, and if not add the Default.
>> >
>> > How do i do this? I can't find anything on google :-/
>> >
>> > Thanks,
>> >
>> > Pieter
>> >
>> >
>>
>|||Try,
declare @.sql nvarchar(4000)
declare @.cnstname sysname
select
@.cnstname = [name]
from
sysobjects as so
where
xtype = 'D'
and parent_obj = object_id('dbo.t')
and col_name(parent_obj, info) = 'colB'
if @.cnstname is not null
print @.cnstname
else
print 'no default for column [colB] in table [t].'
go
AMB
"DraguVaso" wrote:
> For a script that should update some table-definitions, I would like to know
> how i can now if a DEFAULT exists for a given row in a table.
> for exemple:
> ALTER TABLE MyTable ADD
> CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
> This adds the Default NEWID() to the row MyRow in the table MyTable.
> But when i run this query a second time, i get a warning ("Column already
> has a DEFAULT bound to it.") that it already exists. So I would like my
> query check first if it is there or not, and if not add the Default.
> How do i do this? I can't find anything on google :-/
> Thanks,
> Pieter
>
>|||Ok thanks! Works fine!
The solution of Alejandro works fine too! thanks a lot guys!
"Jens Süßmeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote in
message news:%23BWTRFLVFHA.3152@.TK2MSFTNGP12.phx.gbl...
> Your are right, you can try that from Dejan Serka:
> select
> db_name() as CONSTRAINT_CATALOG
> ,user_name(c_obj.uid) as CONSTRAINT_SCHEMA
> ,c_obj.name as CONSTRAINT_NAME
> ,com.text as DEFAULT_CLAUSE
> from
> sysobjects c_obj
> ,syscomments com
> where
> c_obj.uid = user_id()
> and c_obj.id = com.id
> and c_obj.xtype = 'D'
> Found under
>
http://sql.reproms.si/data/podatki/dejan/INFORMATION_SCHEMA%20Views%20for%20Default%20Constraints.sql
> to change to standard beaviour of the Information Views,
>
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
> "DraguVaso" <pietercoucke@.hotmail.com> schrieb im Newsbeitrag
> news:OluNH3KVFHA.1452@.TK2MSFTNGP14.phx.gbl...
> > hi,
> >
> > Unfortunately it works only for CHECK, UNIQUE, PRIMARY KEY, or FOREIGN
> > KEY,
> > and not for DEFAULT :-(
> >
> > any other idea?
> >
> > "Jens Süßmeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote
> > in
> > message news:ew4NznKVFHA.3540@.TK2MSFTNGP15.phx.gbl...
> >> IF NOT EXISTS(SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE
> >> Constraint_Name like 'DF_MyTable_MyRow'
> >> ALTER TABLE MyTable ADD
> >> CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
> >>
> >> HTH, Jens Suessmeyer.
> >>
> >> --
> >> http://www.sqlserver2005.de
> >> --
> >>
> >>
> >> "DraguVaso" <pietercoucke@.hotmail.com> schrieb im Newsbeitrag
> >> news:Oct$xeKVFHA.2520@.TK2MSFTNGP09.phx.gbl...
> >> > For a script that should update some table-definitions, I would like
to
> >> > know
> >> > how i can now if a DEFAULT exists for a given row in a table.
> >> >
> >> > for exemple:
> >> IF NOT EXISTS(SELECT * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE
> >> Constraint_Name like 'DF_MyTable_MyRow'
> >> ALTER TABLE MyTable ADD
> >> CONSTRAINT [DF_MyTable_MyRow] DEFAULT (newid()) FOR MyRow'
> >> >
> >> > This adds the Default NEWID() to the row MyRow in the table MyTable.
> >> > But when i run this query a second time, i get a warning ("Column
> > already
> >> > has a DEFAULT bound to it.") that it already exists. So I would like
my
> >> > query check first if it is there or not, and if not add the Default.
> >> >
> >> > How do i do this? I can't find anything on google :-/
> >> >
> >> > Thanks,
> >> >
> >> > Pieter
> >> >
> >> >
> >>
> >>
> >
> >
>