Showing posts with label schema. Show all posts
Showing posts with label schema. Show all posts

Friday, March 30, 2012

How to create Schema with FOR XML EXPLICIT option?

Hi,
i have this query:
SELECT 1 as Tag, NULL as Parent,
nomecampo as [label!1!for],
etichetta as [label!1!],
null as [input!2!id],
null as [input!2!type],
null as [input!2!name],
null as [input!2!value]
FROM t_campiaree
UNION ALL
select 2 as tag,
0 as parent,
null as [label!2!for],
null as [label!2!],
id as [input!2!id],
tipointerfaccia as [input!2!type],
nomecampo as [input!2!name],
'' [input!2!value]
from t_campiaree
FOR XML EXPLICIT
and the results is this:
<label for=3D"nome">Nome</label>
<label for=3D"cognome">Cognome</label>
<label for=3D"eta">Et=E0</label>
<input id=3D"1" type=3D"input" name=3D"nome" value=3D"" />
<input id=3D"2" type=3D"input" name=3D"cognome" value=3D"" />
<input id=3D"3" type=3D"input" name=3D"eta" value=3D"" />
now, how i can create schema for this xml file?
the XMLSCHEMA option don't work with EXPLICIT mode right?Hello maurox,

> the XMLSCHEMA option don't work with EXPLICIT mode right?
Nope, not yet anyway. If you can save the query results to a file and if
you have the .NET SDK installed, you can use XSD.EXE to infer a schema.
Thank you,
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/|||thank kent.

>Nope, not yet anyway. If you can save the query results to a file and if
>you have the .NET SDK installed, you can use XSD.EXE to infer a schema.
it is the only solution?
i try with xsd.exe but i don't know how set the type of each
attribute..(i.e. attribute 'id' is integer but in the schema generated
is string)...sql

How to create Schema with FOR XML EXPLICIT option?

Hi,
i have this query:
SELECT 1 as Tag, NULL as Parent,
nomecampo as [label!1!for],
etichetta as [label!1!],
null as [input!2!id],
null as [input!2!type],
null as [input!2!name],
null as [input!2!value]
FROM t_campiaree
UNION ALL
select 2 as tag,
0 as parent,
null as [label!2!for],
null as [label!2!],
id as [input!2!id],
tipointerfaccia as [input!2!type],
nomecampo as [input!2!name],
'' [input!2!value]
from t_campiaree
FOR XML EXPLICIT
and the results is this:
<label for=3D"nome">Nome</label>
<label for=3D"cognome">Cognome</label>
<label for=3D"eta">Et=E0</label>
<input id=3D"1" type=3D"input" name=3D"nome" value=3D"" />
<input id=3D"2" type=3D"input" name=3D"cognome" value=3D"" />
<input id=3D"3" type=3D"input" name=3D"eta" value=3D"" />
now, how i can create schema for this xml file?
the XMLSCHEMA option don't work with EXPLICIT mode right?
Hello maurox,

> the XMLSCHEMA option don't work with EXPLICIT mode right?
Nope, not yet anyway. If you can save the query results to a file and if
you have the .NET SDK installed, you can use XSD.EXE to infer a schema.
Thank you,
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/
|||thank kent.

>Nope, not yet anyway. If you can save the query results to a file and if
>you have the .NET SDK installed, you can use XSD.EXE to infer a schema.
it is the only solution?
i try with xsd.exe but i don't know how set the type of each
attribute..(i.e. attribute 'id' is integer but in the schema generated
is string)...

How to create schem

Hello all,
I've always tried to write my SQL script so that they could run
multiple times without error so when I was creating a new schema i get
an error
USE AdventureWorks
GO
IF NOT EXISTS(SELECT * FROM sys.schemas where [name] = 'temp')
CREATE SCHEMA temp AUTHORIZATION dbo
--END IF
GO
this code works
USE AdventureWorks
GO
IF NOT EXISTS(SELECT * FROM sys.schemas where [name] = 'temp')
PRINT 'CREATE SCHEMA temp AUTHORIZATION dbo'
--END IF
GO
and this code works
USE AdventureWorks
GO
CREATE SCHEMA temp AUTHORIZATION dbo
GO
can anyone shed some light on this.
Thanks in advance for your help.
Regards,
HJ
Try something like:
USE AdventureWorks
GO
IF NOT EXISTS(SELECT * FROM sys.schemas where [name] =
'temp')
EXEC('CREATE SCHEMA temp AUTHORIZATION dbo')
-Sue
On 23 Mar 2006 09:26:13 -0800, hanklvr@.yahoo.com wrote:

>Hello all,
>I've always tried to write my SQL script so that they could run
>multiple times without error so when I was creating a new schema i get
>an error
>USE AdventureWorks
>GO
>IF NOT EXISTS(SELECT * FROM sys.schemas where [name] = 'temp')
> CREATE SCHEMA temp AUTHORIZATION dbo
>--END IF
>GO
>this code works
>USE AdventureWorks
>GO
>IF NOT EXISTS(SELECT * FROM sys.schemas where [name] = 'temp')
> PRINT 'CREATE SCHEMA temp AUTHORIZATION dbo'
>--END IF
>GO
>and this code works
>USE AdventureWorks
>GO
>CREATE SCHEMA temp AUTHORIZATION dbo
>GO
>can anyone shed some light on this.
>Thanks in advance for your help.
>Regards,
>HJ

How to create schem

Hello all,
I've always tried to write my SQL script so that they could run
multiple times without error so when I was creating a new schema i get
an error
USE AdventureWorks
GO
IF NOT EXISTS(SELECT * FROM sys.schemas where [name] = 'temp')
CREATE SCHEMA temp AUTHORIZATION dbo
--END IF
GO
this code works
USE AdventureWorks
GO
IF NOT EXISTS(SELECT * FROM sys.schemas where [name] = 'temp')
PRINT 'CREATE SCHEMA temp AUTHORIZATION dbo'
--END IF
GO
and this code works
USE AdventureWorks
GO
CREATE SCHEMA temp AUTHORIZATION dbo
GO
can anyone shed some light on this.
Thanks in advance for your help.
Regards,
HJTry something like:
USE AdventureWorks
GO
IF NOT EXISTS(SELECT * FROM sys.schemas where [name] =
'temp')
EXEC('CREATE SCHEMA temp AUTHORIZATION dbo')
-Sue
On 23 Mar 2006 09:26:13 -0800, hanklvr@.yahoo.com wrote:

>Hello all,
>I've always tried to write my SQL script so that they could run
>multiple times without error so when I was creating a new schema i get
>an error
>USE AdventureWorks
>GO
>IF NOT EXISTS(SELECT * FROM sys.schemas where [name] = 'temp')
> CREATE SCHEMA temp AUTHORIZATION dbo
>--END IF
>GO
>this code works
>USE AdventureWorks
>GO
>IF NOT EXISTS(SELECT * FROM sys.schemas where [name] = 'temp')
> PRINT 'CREATE SCHEMA temp AUTHORIZATION dbo'
>--END IF
>GO
>and this code works
>USE AdventureWorks
>GO
>CREATE SCHEMA temp AUTHORIZATION dbo
>GO
>can anyone shed some light on this.
>Thanks in advance for your help.
>Regards,
>HJ

How to create schem

Hello all,
I've always tried to write my SQL script so that they could run
multiple times without error so when I was creating a new schema i get
an error
USE AdventureWorks
GO
IF NOT EXISTS(SELECT * FROM sys.schemas where [name] = 'temp')
CREATE SCHEMA temp AUTHORIZATION dbo
--END IF
GO
this code works
USE AdventureWorks
GO
IF NOT EXISTS(SELECT * FROM sys.schemas where [name] = 'temp')
PRINT 'CREATE SCHEMA temp AUTHORIZATION dbo'
--END IF
GO
and this code works
USE AdventureWorks
GO
CREATE SCHEMA temp AUTHORIZATION dbo
GO
can anyone shed some light on this.
Thanks in advance for your help.
Regards,
HJTry something like:
USE AdventureWorks
GO
IF NOT EXISTS(SELECT * FROM sys.schemas where [name] ='temp')
EXEC('CREATE SCHEMA temp AUTHORIZATION dbo')
-Sue
On 23 Mar 2006 09:26:13 -0800, hanklvr@.yahoo.com wrote:
>Hello all,
>I've always tried to write my SQL script so that they could run
>multiple times without error so when I was creating a new schema i get
>an error
>USE AdventureWorks
>GO
>IF NOT EXISTS(SELECT * FROM sys.schemas where [name] = 'temp')
> CREATE SCHEMA temp AUTHORIZATION dbo
>--END IF
>GO
>this code works
>USE AdventureWorks
>GO
>IF NOT EXISTS(SELECT * FROM sys.schemas where [name] = 'temp')
> PRINT 'CREATE SCHEMA temp AUTHORIZATION dbo'
>--END IF
>GO
>and this code works
>USE AdventureWorks
>GO
>CREATE SCHEMA temp AUTHORIZATION dbo
>GO
>can anyone shed some light on this.
>Thanks in advance for your help.
>Regards,
>HJ

Friday, March 23, 2012

How to Create an XSD/XML Schema file?

I am trying to load the following XML file into a database table. I
receive the file from an external source exactly as follows:
<list type='full' level='state' val='CA'>
<ac val='714'>
<ph val='2011882' />
<ph val='2013327' />
<ph val='2016543' />
<ph val='2017632' />
<ph val='2017656' />
<ph val='2018788' />
<ph val='2018211' />
<ph val='2019345' />
</ac>
</list>
I have a SQL Server 2000 running with a Table named PHONE that has only
one column:
PHONENUMBER <VARCHAR 10> (Sample Data: 7025556511)
I am new to XML as it works with SQL Server so I have the following
issues:
(1) Because the external file can have millions of PH records, I would
like to load the data into the SQL Server table using OPENXML and the
SQLXMLBulkLoad object (I understand this is a desirable option for
performance).
(2) How should the XSD Mapping Schema file be formatted to
combine/merge the AC and PH values into the PHONE table as one piece of
data?
(3) The bottom line is 'What will the XSD Mapping Schema file look
like'?
Any help would be greatly appreciated.> I am trying to load the following XML file into a database table. I
> receive the file from an external source exactly as follows:
> <list type='full' level='state' val='CA'>
> <ac val='714'>
> <ph val='2011882' />
> <ph val='2013327' />
> <ph val='2016543' />
> <ph val='2017632' />
> <ph val='2017656' />
> <ph val='2018788' />
> <ph val='2018211' />
> <ph val='2019345' />
> </ac>
> </list>
Since I am a developer, I am kind of weak on these XML-related features of
SQL Server. But since no one else has answered your post, I will tell you
what I would try as a developer.
In any of the .NET programming languages, you have this thing called a
DataSet object, which represents a series of DataTable objects. A DataTable
represents a resultset, like you would get from a SELECT statement. A
DataSet can contain any number of DataTables, and can even enforce
referential integrity between them. A DataSet object has a OpenXML or
ReadXML method (I forget which -- I haven't slept in days) where you can
pass the filename of your XML file, and your DataSet will be populated with
the relational structure and data that's represented inside the XML file.
Then you enumerate all the DataTable objects inside the DataSet.Tables
collection. For each DataTable, you build a InsertCommand or UpdateCommand
for a DataAdapter (the thing that issues commands to the data store)
Then you say DataSet.Update() and presto, all your data is in the database.
In theory.
Peace & happy computing,
Mike Labosh, MCSD MCT
Owner, vbSensei.Com
"Escriba coda ergo sum." -- vbSensei|||<dsijta@.netscape.net> wrote in message
news:1140837455.552719.197710@.v46g2000cwv.googlegroups.com...
>I am trying to load the following XML file into a database table. I
> receive the file from an external source exactly as follows:
> <list type='full' level='state' val='CA'>
> <ac val='714'>
> <ph val='2011882' />
> <ph val='2013327' />
> <ph val='2016543' />
> <ph val='2017632' />
> <ph val='2017656' />
> <ph val='2018788' />
> <ph val='2018211' />
> <ph val='2019345' />
> </ac>
> </list>
> I have a SQL Server 2000 running with a Table named PHONE that has only
> one column:
> PHONENUMBER <VARCHAR 10> (Sample Data: 7025556511)
> I am new to XML as it works with SQL Server so I have the following
> issues:
> (1) Because the external file can have millions of PH records, I would
> like to load the data into the SQL Server table using OPENXML and the
> SQLXMLBulkLoad object (I understand this is a desirable option for
> performance).
> (2) How should the XSD Mapping Schema file be formatted to
> combine/merge the AC and PH values into the PHONE table as one piece of
> data?
> (3) The bottom line is 'What will the XSD Mapping Schema file look
> like'?
> Any help would be greatly appreciated.
>
Here's an example of an XSD for the document you posted. Many XML utilities
will generate schemas automatically for you. This one I produced using SQL
Server 2005 Integration Services.
An XSD only validates the format. It doesn't perform any transformations.
<?xml version="1.0"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="list">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="ac">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="ph">
<xs:complexType>
<xs:attribute name="val" type="xs:unsignedInt"
use="optional" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="val" type="xs:unsignedShort" use="optional"
/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="type" type="xs:string" use="optional" />
<xs:attribute name="level" type="xs:string" use="optional" />
<xs:attribute name="val" type="xs:string" use="optional" />
</xs:complexType>
</xs:element>
</xs:schema>
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||You can also this free tool (from MS):
http://apps.gotdotnet.com/xmltools/...e/overview.html
http://www.gotdotnet.com/Community/...0c-f24b91e47228
-oj
<dsijta@.netscape.net> wrote in message
news:1140837455.552719.197710@.v46g2000cwv.googlegroups.com...
>I am trying to load the following XML file into a database table. I
> receive the file from an external source exactly as follows:
> <list type='full' level='state' val='CA'>
> <ac val='714'>
> <ph val='2011882' />
> <ph val='2013327' />
> <ph val='2016543' />
> <ph val='2017632' />
> <ph val='2017656' />
> <ph val='2018788' />
> <ph val='2018211' />
> <ph val='2019345' />
> </ac>
> </list>
> I have a SQL Server 2000 running with a Table named PHONE that has only
> one column:
> PHONENUMBER <VARCHAR 10> (Sample Data: 7025556511)
> I am new to XML as it works with SQL Server so I have the following
> issues:
> (1) Because the external file can have millions of PH records, I would
> like to load the data into the SQL Server table using OPENXML and the
> SQLXMLBulkLoad object (I understand this is a desirable option for
> performance).
> (2) How should the XSD Mapping Schema file be formatted to
> combine/merge the AC and PH values into the PHONE table as one piece of
> data?
> (3) The bottom line is 'What will the XSD Mapping Schema file look
> like'?
> Any help would be greatly appreciated.
>|||> http://apps.gotdotnet.com/xmltools/...e/overview.html
WOAH! COOL!!
--
Peace & happy computing,
Mike Labosh, MCSD MCT
Owner, vbSensei.Com
"Escriba coda ergo sum." -- vbSensei|||Hi -
For an example of a XML schema generator utility, see:
http://www.stylusstudio.com/autogen_xsd.html
It shows how to create an XML schema from an XML instance document.
hope that helps.
Sincerely,
The Stylus Studio Team
http://www.stylusstudio.comsql

How to create an xml schema collection from a file

Hello all.
I'm trying to create an xml schema collection from a file, using this code
DROP XML SCHEMA COLLECTION gandy
DECLARE @.xml xml
SELECT @.xml = BulkColumn FROM openrowset(Bulk 'P04-S01.xsl', SINGLE_BLOB) as
x
CREATE XML SCHEMA COLLECTION gandy AS @.xml
The problem is that after running this statements SQL Server 2005 gives this
error
Msg 2378, Level 16, State 1, Line 4
Expected XML schema document
What is the problem?
The xslt document is well formed and working (I used it with Altova XML Spy
to apply the transformation).
Thanks
André Giltry something like this
declare @.string varchar(MAX)
declare @.xml varchar(MAX)
select @.string ='Create xml Schema Collection MySchemaCollections as '''
SELECT @.xml = replace(BulkColumn,CHAR(39),CHAR(39)+CHA
R(39)) FROM
openrowset(Bulk ''P04-S01.xsl'', SINGLE_BLOB) as x
select @.string=@.string +@.xml +''''
--print @.string
exec(@.string)
I am not sure about the wisdom of doing something like this though.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Andr Gil" <AndrGil@.discussions.microsoft.com> wrote in message
news:8E8AB17D-4D56-442B-A9D1-0459E86A1215@.microsoft.com...
> Hello all.
> I'm trying to create an xml schema collection from a file, using this code
> DROP XML SCHEMA COLLECTION gandy
> DECLARE @.xml xml
> SELECT @.xml = BulkColumn FROM openrowset(Bulk 'P04-S01.xsl', SINGLE_BLOB)
> as x
> CREATE XML SCHEMA COLLECTION gandy AS @.xml
> The problem is that after running this statements SQL Server 2005 gives
> this
> error
> Msg 2378, Level 16, State 1, Line 4
> Expected XML schema document
> What is the problem?
> The xslt document is well formed and working (I used it with Altova XML
> Spy
> to apply the transformation).
> Thanks
> Andr Gil|||Interrupting my skiing :-)
Why would you want to load an XSLT transformation as a schema file? They
have nothing in common.
Try loading an actual XML Schema file...
Best regards
Michael
"Andr Gil" <AndrGil@.discussions.microsoft.com> wrote in message
news:8E8AB17D-4D56-442B-A9D1-0459E86A1215@.microsoft.com...
> Hello all.
> I'm trying to create an xml schema collection from a file, using this code
> DROP XML SCHEMA COLLECTION gandy
> DECLARE @.xml xml
> SELECT @.xml = BulkColumn FROM openrowset(Bulk 'P04-S01.xsl', SINGLE_BLOB)
> as x
> CREATE XML SCHEMA COLLECTION gandy AS @.xml
> The problem is that after running this statements SQL Server 2005 gives
> this
> error
> Msg 2378, Level 16, State 1, Line 4
> Expected XML schema document
> What is the problem?
> The xslt document is well formed and working (I used it with Altova XML
> Spy
> to apply the transformation).
> Thanks
> Andr Gil

How to create an xml schema collection from a file

Hello all.
I'm trying to create an xml schema collection from a file, using this code
DROP XML SCHEMA COLLECTION gandy
DECLARE @.xml xml
SELECT @.xml = BulkColumn FROM openrowset(Bulk 'P04-S01.xsl', SINGLE_BLOB) as x
CREATE XML SCHEMA COLLECTION gandy AS @.xml
The problem is that after running this statements SQL Server 2005 gives this
error
Msg 2378, Level 16, State 1, Line 4
Expected XML schema document
What is the problem?
The xslt document is well formed and working (I used it with Altova XML Spy
to apply the transformation).
Thanks
André Gil
try something like this
declare @.string varchar(MAX)
declare @.xml varchar(MAX)
select @.string ='Create xml Schema Collection MySchemaCollections as '''
SELECT @.xml = replace(BulkColumn,CHAR(39),CHAR(39)+CHAR(39)) FROM
openrowset(Bulk ''P04-S01.xsl'', SINGLE_BLOB) as x
select @.string=@.string +@.xml +''''
--print @.string
exec(@.string)
I am not sure about the wisdom of doing something like this though.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Andr Gil" <AndrGil@.discussions.microsoft.com> wrote in message
news:8E8AB17D-4D56-442B-A9D1-0459E86A1215@.microsoft.com...
> Hello all.
> I'm trying to create an xml schema collection from a file, using this code
> DROP XML SCHEMA COLLECTION gandy
> DECLARE @.xml xml
> SELECT @.xml = BulkColumn FROM openrowset(Bulk 'P04-S01.xsl', SINGLE_BLOB)
> as x
> CREATE XML SCHEMA COLLECTION gandy AS @.xml
> The problem is that after running this statements SQL Server 2005 gives
> this
> error
> Msg 2378, Level 16, State 1, Line 4
> Expected XML schema document
> What is the problem?
> The xslt document is well formed and working (I used it with Altova XML
> Spy
> to apply the transformation).
> Thanks
> Andr Gil
|||Interrupting my skiing :-)
Why would you want to load an XSLT transformation as a schema file? They
have nothing in common.
Try loading an actual XML Schema file...
Best regards
Michael
"Andr Gil" <AndrGil@.discussions.microsoft.com> wrote in message
news:8E8AB17D-4D56-442B-A9D1-0459E86A1215@.microsoft.com...
> Hello all.
> I'm trying to create an xml schema collection from a file, using this code
> DROP XML SCHEMA COLLECTION gandy
> DECLARE @.xml xml
> SELECT @.xml = BulkColumn FROM openrowset(Bulk 'P04-S01.xsl', SINGLE_BLOB)
> as x
> CREATE XML SCHEMA COLLECTION gandy AS @.xml
> The problem is that after running this statements SQL Server 2005 gives
> this
> error
> Msg 2378, Level 16, State 1, Line 4
> Expected XML schema document
> What is the problem?
> The xslt document is well formed and working (I used it with Altova XML
> Spy
> to apply the transformation).
> Thanks
> Andr Gil

Wednesday, March 21, 2012

How to create an object without being the owner of the schema

Hi

I have a schema called Accounts owned by fred

User bob has create procedure permission as follows:

grant create procedure to bob

bob would like to create a procedure in schema Accounts.

When he issues create proc Accounts.sp_proc.... it fails with:

Msg 2760, Level 16, State 1, Procedure sp_proc, Line 3
The specified schema name "Accounts" either does not exist or you do not have permission to use it.

What permission do I need to grant bob in order to allow this?

Thanks

The answer is in Books Online; look for the Permissions section in the CREATE PROCEDURE article:

http://msdn2.microsoft.com/en-us/library/ms187926(SQL.90).aspx

Thanks
Laurentiu

|||

Thanks Laurentiu, I couldn't see the wood for the trees.

In case anyone else is interested I needed to run:

GRANT ALTER ON SCHEMA::Accounts TO bob

sql

Monday, March 12, 2012

How to create a new schema

How can I create a new schema inside a database from Managment studio express.

Also can someone explain me the concept of schema clearly. If database is like a house, then is schema like a room in it ?

if you use the metaphor House, you could say that the house is the database, the appartments are the schemas, though they can be owned by someone on have kinds of objects in them (tables, views --> rooms). If the owner of the appartment or the actual person who rent the appartment wants to quit the contract, you will first have to find another owner / contract partner vefore moving out of the appartment.

http://msdn2.microsoft.com/en-us/library/ms190387.aspx

Jens K. Suessmeyer.

http://www.sqlserver2005.de
|||

Thanks. Have another question. When we create a new schema is some part of database memory allocated to it and hence having too many schemas... leads to memory fragmentation problems and hence not efficient ?

Friday, March 9, 2012

How to create a CLR integrated trigger on table in schema?

In CLR integrated trigger:

If I want to make a trigger:
- For Insert
- With name: NewEmployeeInserted
- On table dbo.Employees

I add the following attribute above the desired .net method logic:
[SqlTrigger(Event = "For Insert", Name = "NewEmployeeInserted", Target = "Employees")]

How to make a trigger on for example: Production.Employees table?
where Production is the schema where this table resides.

Thank you.

Hi,

this was discussed in an earlier thread: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=132062&SiteID=1

Normally you should be able to only prefix the Schema before the table target.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de