Groups | Blog | Home
all groups > sql server (microsoft) > july 2006 >

sql server (microsoft) : T-SQL statement to set field predefined value and a synchro question


polocar
7/24/2006 1:11:32 PM
Hi,
I have 3 problems regarding SQL Server 2005...

1) I would like to create a SQL Server 2005 database with a T-SQL
Query.
I have found an example in the MSDN library to create a SQLMobile
database:

CREATE DATABASE SQLMobile
GO
USE SQLMobile
GO
CREATE TABLE MembershipData (MemberID INTEGER IDENTITY (1,1) PRIMARY
KEY, MemberName NVarChar (50))
CREATE TABLE FlightData (MemberID INTEGER FOREIGN KEY REFERENCES
MembershipData(MemberID), Destination NVarChar (50), FlightStatus
NVarChar(50), ArrivalDate DATETIME, FlownMiles INTEGER)

If I wanted to set a predefined value for every field of the the
MembershipData and FlightData tables, how should I modify the 2
statements? What should I add?

2) When I create a publication of this SQLMobile and I select the 2
tables as articles to publish, will be published the relationship too?
(between the MemberID field of MembershipData and the MemberID of
FlightData)? If not, is there a way to do it?

3) Suppose that now I have a SQLMobile database (of SQL Server type) in
my PC, and a SQLMobile one (of SQL Server Mobile type, synchronized
with merge replication to the PC's one) in a pocket PC.
Suppose that I delete the MembershipData record with MemberID = 1 in
the PC database (MembershipData is the parent table) and that, after 1
hour, I add a FlightData record with MemberID = 1 in the pocket PC (I
can do it because the MembershipData record with MemberID = 1 exists
yet in the PPC).
When I synchronize the 2 database, what happens?
Is a PC database MembershipData record with MemberID = 1 re-created
(and created the FlightData record with MemberID = 1 too), or is the
PPC database MembershipData record with MemberID = 1 deleted?

4) If I exchange the temporal sequence of the 2 operations, and first I
add the PPC database FlightData record with MemberID = 1, and after 1
hour I delete the PC database MembershipData record with MemberID = 1
(and finally I synchronize), does something change respect to the
previous situation?

Thank you very much
polocar
7/25/2006 9:54:11 AM
Ok, I have found the answer to the first question.
To create a table indicating the fields' default values, the code is:

CREATE DATABASE SQLMobile
GO
USE SQLMobile
GO
CREATE TABLE MembershipData (MemberID INTEGER IDENTITY (1,1) PRIMARY
KEY, MemberName NVarChar (50) default '')
CREATE TABLE FlightData (MemberID INTEGER FOREIGN KEY REFERENCES
MembershipData(MemberID), Destination NVarChar (50) default '',
FlightStatus
NVarChar(50) default '', ArrivalDate DATETIME default '25/07/2006',
FlownMiles INTEGER default 1000)

In other words, it is sufficient to add the "default" keyword followed
by the desired value.

As I'm not able (and I don't know why) to create a subscription in my
PPC (to subscript the PPC SQLMobile database to the publication of the
PC SQLMobile one), I can't do any test to answer questions 2, 3 and 4
yet...
AddThis Social Bookmark Button