MySQL Conversion To MS SQL - Problems With Syntax As Well As With Pk/fk Relationships

Apr 9, 2006

Hello all,

For those of you who are able to assist, I'd like to thank you in advance right now. This is a pretty big problem for me.

First let me setup what it is I'm trying to do before I describe the problem in detail. This is part of a semester-long Software Engineering project for my SE class at school. Now, I've got a month for this project, but the database part of it is something I'm trying to get done by this week. Our team is using GoDaddy to host our account and so to simplify our problems with using Visual Studio and MySQL we're switching over to MS SQL, where our code works.

Okay, onto the specifics: I'm used to using a database modeling program called DBDesigner4. Unfortunately, they're support forums have been closed down (fabFORCE.net) and I've spoken with a GoDaddy representative and their servers don't allow me to directly connect with my modeling program and create the schema/tables using the program. However, the program does export to a MySQL table creation script or even an MDB XML file (MSAcess I believe). I'm trying to hand convert the creation script over to MS SQL syntax and I'm having alot of problems (please bear with me, I've never messed with MS SQL before).

For your reference, I'm going to display the actual MySQL script here (just skip this section if you'd like to see the actual problem below):


Code:


CREATE TABLE Addresses (
address_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
address_line1 VARCHAR(30) NOT NULL,
address_line2 VARCHAR(30) NULL,
address_city VARCHAR(30) NOT NULL,
address_state VARCHAR(2) NOT NULL,
address_zip MEDIUMINT UNSIGNED NOT NULL,
PRIMARY KEY(address_id)
)
TYPE=InnoDB;

CREATE TABLE Broadcasts (
broadcast_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
address_id INTEGER UNSIGNED NOT NULL,
broadcast_title VARCHAR(30) NOT NULL,
broadcast_message VARCHAR(255) NOT NULL,
broadcast_image VARCHAR(255) NOT NULL,
broadcast_date_posted DATETIME NOT NULL,
broadcast_date_expires DATETIME NOT NULL,
broadcast_date_archived DATETIME NULL,
broadcast_clicks BIGINT NOT NULL DEFAULT 0,
broadcast_type ENUM('promo', 'announcement', 'other') NOT NULL DEFAULT 'promo',
broadcast_link VARCHAR(255) NULL,
PRIMARY KEY(broadcast_id),
INDEX Broadcasts_FKIndex1(address_id)
)
TYPE=InnoDB;

CREATE TABLE Classes (
user_id INTEGER UNSIGNED NOT NULL,
subject_id INTEGER UNSIGNED NOT NULL,
class_grade INTEGER UNSIGNED NOT NULL DEFAULT 100,
class_tardies INTEGER UNSIGNED NOT NULL DEFAULT 0,
class_absences INTEGER UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY(user_id, subject_id),
INDEX Users_has_Sections_FKIndex1(user_id),
INDEX Classes_FKIndex2(subject_id)
);

CREATE TABLE Classes_have_Grades (
subject_id INTEGER UNSIGNED NOT NULL,
user_id INTEGER UNSIGNED NOT NULL,
grade_id INTEGER UNSIGNED NOT NULL,
PRIMARY KEY(subject_id, user_id, grade_id),
INDEX Grades_has_Classes_FKIndex1(grade_id),
INDEX Grades_has_Classes_FKIndex2(user_id, subject_id)
);

CREATE TABLE Grades (
grade_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
grade INTEGER UNSIGNED NOT NULL,
grade_type ENUM('h', 'q', 't') NOT NULL,
grade_desc VARCHAR(50) NOT NULL,
PRIMARY KEY(grade_id)
);

CREATE TABLE Locations (
loc_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
address_id INTEGER UNSIGNED NOT NULL,
location_id VARCHAR(20) NOT NULL,
location_name VARCHAR(25) NOT NULL,
PRIMARY KEY(loc_id),
INDEX Locations_FKIndex1(address_id)
)
TYPE=InnoDB;

CREATE TABLE Passports (
passport_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
user_id INTEGER UNSIGNED NOT NULL,
location_id INTEGER UNSIGNED NOT NULL,
passport_user VARCHAR(7) NOT NULL,
passport_code VARCHAR(32) NOT NULL,
passport_access ENUM('student', 'faculty', 'admin') NOT NULL DEFAULT 'student',
passport_tries TINYINT UNSIGNED NOT NULL DEFAULT 0,
passport_locked BOOL NOT NULL DEFAULT 'false',
passport_lastaccess DATETIME NULL,
PRIMARY KEY(passport_id),
INDEX Passports_FKIndex1(location_id),
INDEX Passports_FKIndex2(user_id)
)
TYPE=InnoDB;

CREATE TABLE Subjects (
subject_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
subject_name VARCHAR(50) NOT NULL,
subject_offered BOOL NOT NULL,
subject_grade ENUM('1', '2', '3', '4', '5', '6') NOT NULL,
PRIMARY KEY(subject_id)
)
TYPE=InnoDB;

CREATE TABLE Users (
user_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
address_id INTEGER UNSIGNED NOT NULL,
user_fname VARCHAR(20) NOT NULL,
user_mletter VARCHAR(1) NULL,
user_lname VARCHAR(20) NOT NULL,
user_grade FLOAT NOT NULL,
user_type ENUM('student', 'faculty') NOT NULL DEFAULT 'student',
user_balance FLOAT NOT NULL,
user_phone CHAR(15) NOT NULL,
user_email VARCHAR(50) NOT NULL,
PRIMARY KEY(user_id),
INDEX Users_FKIndex1(address_id)
)
TYPE=InnoDB;



That script runs just fine on MySQL and generates my application's tables with the correct relationships intact, indexes, etc.

However, as I said, I need this setup in MS SQL with a few additional checks and I've hand converted most of this, not knowing how to properly maintain primary keys or foreign keys:


Code:


CREATE TABLE Addresses
(
address_id
INT
PRIMARY KEY
IDENTITY(1,1)
NOT NULL,

address_line1
VARCHAR(30)
NOT NULL,

address_line2
VARCHAR(30)
NULL,

address_city
VARCHAR(30)
NOT NULL,

address_state
VARCHAR(2)
NOT NULL,

address_zip
ZIPCODE
CONSTRAINT CK_address_zip
CHECK (address_zip LIKE '[0-9][0-9][0-9][0-9][0-9] ')
)

CREATE TABLE Broadcasts
(
broadcast_id
INT
PRIMARY KEY
IDENTITY(1,1)
NOT NULL,

address_id
INT
NOT NULL,

broadcast_title
VARCHAR(30)
NOT NULL,

broadcast_message
VARCHAR(255)
NOT NULL,

broadcast_image
VARCHAR(255)
NOT NULL,

broadcast_date_posted
DATETIME
NOT NULL,

broadcast_date_expires
DATETIME
NOT NULL,

broadcast_date_archived
DATETIME
NULL,

broadcast_clicks
INT
NOT NULL
DEFAULT 0,

broadcast_type
CHAR(1)
NOT NULL
DEFAULT(‘a’),

broadcast_link
VARCHAR(255)
NULL
)

CREATE TABLE Classes
(
user_id
INT
PRIMARY KEY
NOT NULL,

subject_id
INT
NOT NULL,

class_grade
INT
NOT NULL
DEFAULT 100,

class_tardies
INT
NOT NULL
DEFAULT 0,

class_absences
INT
NOT NULL
DEFAULT 0
)

CREATE TABLE Classes_have_Grades
(
subject_id
INT
NOT NULL,

user_id
INT PRIMARY KEY
NOT NULL,

grade_id
INT
NOT NULL
)

CREATE TABLE Grades
(
grade_id
INT
PRIMARY KEY
IDENTITY(1,1)
NOT NULL,

Grade
INT
NOT NULL,

grade_type
CHAR(1)
NOT NULL
DEFAULT(‘h’),

grade_desc
VARCHAR(50)
NOT NULL
)

CREATE TABLE Locations
(
loc_id
INT
PRIMARY KEY
IDENTITY(1,1)
NOT NULL,

address_id
INT
NOT NULL,

location_id
VARCHAR(20)
NOT NULL,

location_name
VARCHAR(25)
NOT NULL
)

CREATE TABLE Passports
(
passport_id
INT
PRIMARY KEY
IDENTITY(1,1)
NOT NULL,

user_id
USERID
NOT NULL
CONSTRAINT CK_user_id
CHECK (user_id LIKE '[A-Z][A-Z][A-Z][0-9][0-9][0-9][0-9]'),

location_id
INT
NOT NULL,

passport_user
VARCHAR(7)
NOT NULL,

passport_code
VARCHAR(32)
NOT NULL,

passport_access
CHAR(1)
NOT NULL
DEFAULT(‘s’),

passport_tries
TINYINT
NOT NULL
DEFAULT(0),

passport_locked
BOOL
NOT NULL
DEFAULT(false),

passport_lastaccess
DATETIME
NULL
)

CREATE TABLE Subjects
(
subject_id
INT
PRIMARY KEY
IDENTITY(1,1)
NOT NULL,

subject_name
VARCHAR(50)
NOT NULL,

subject_offered
BOOL
NOT NULL,

subject_grade
SMALLINT
NOT NULL
DEFAULT 6
)

CREATE TABLE Users
(
user_id
INT
PRIMARY KEY
IDENTITY(1,1)
NOT NULL,

address_id
INT
NOT NULL,

user_fname
VARCHAR(20)
NOT NULL,

user_mletter
CHAR(1)
NULL,

user_lname
VARCHAR(20)
NOT NULL,

user_grade
FLOAT
NOT NULL,

user_type
CHAR(1)
NOT NULL
DEFAULT(‘s’),

user_balance
FLOAT
NOT NULL,

user_phone
CHAR(15)
NOT NULL,

user_email
VARCHAR(50)
NOT NULL
)



Unfortunately, Query Analyzer seems to have a problem and says I have an error in my syntax (on line 74) near "'".

I've googled around and found out a couple of things: TSQL doesn't support enumerations (that I'm aware of - therefore I converted my enum fields to CHAR(1)s or INTs) and that the single quotes surrounding default values is the proper way to do DEFAULT values. I can't figure out for the life of me what's wrong with my syntax and I've been going at this for about 4 hours now.

If you can help me out by explaining how I should properly do the PKs/FKs (I believe there's a keyword REFERENCE(field1, field2) for FKs, but I'm not sure where to place it, etc.) I'll go through the SQL script and try to implement it, but I have a feeling this is going to be a long thread if I do get someone willing to help.

Thanks to everyone who took the time to read this,
Ahad L. Amdani

View 2 Replies


ADVERTISEMENT

MySQL Conversion To MS SQL

Nov 30, 2005

Hello

I am in the process of convering my code from using MySQL to MS SQL

I have queries of the form:

Code:


INSERT INTO <table> (params) VALUES (values)
ON DUPLICATE KEY UPDATE <param1>=<value1>, <param1>=<value1>... <param n>=<value n>


My question is:
Is there an equivalent syntax for such query in MS SQL?
I am looking for a syntax that does this in a single atomic query.
I can always break it down to 2 queries (select + insert/update), but I will do so only after I know there is no equivalent way for it in MS SQL

Also, is there an equivalent syntax for LIMIT X,Y in MS SQL
for quries in the form:

Code:


SELECT <params>
FROM <tables>
WHERE <conditions>
LIMIT X, Y


any help would be appreciated
Thanks

View 2 Replies View Related

Database Conversion: SqlExpress To MySql V5

Jan 25, 2007

Working on trying to support mutliple backend db's against a custom VB6 app. Right now the db is SqlExpress. It's relatively uncomplicated and I just want to move table structures and data over. Using the MySql Migration tool, I am able to authenticate as SA to a server-based instance of SqlExpress, however, only the MS-supplied databases appear as available databases; my databases don't appear. Can't seem to authenticate at all to any local instance of the database, either. Anyone done any successful migrations to MySql through their migration tool?

Rick

View 10 Replies View Related

MySQL To SQL Server 2005 Conversion Table

Mar 20, 2007

Does anyone know of a reference site where I can find a reference table to get a better idea of data type conversions that I should be using?

I have a MySQL 5.0 database which had a lot of tables (mostly empty) that I already have gotten transferred to SQL Server 2005. However, I am suspicious of some of the data type conversions that SQL Server did.

I would really like a good web site to bookmark to help me with this if there is such a reference. Can anyone help?

If not, the most specific example I have right now is a MySQL column that is expecting to accept currency and the MySQL data type is "Double". SQL Server 2005 translated this as a "float" data type. I normally use a "decimal" data type.

- - - -
- Will -
- - - -
http://www.strohlsitedesign.com
http://www.servicerank.com/

View 2 Replies View Related

T-SQL Syntax Error (conversion

May 17, 2004

Hi,

New to the forum here, it seems like this is a good SQL Server resource...

I'm still somewhat in the learning phases of T-SQL coding, and so far what I've learned has been pretty beneficial...a problem i'm having at the moment though, is with some conversion. I created a stored procedure that basically takes all the records from one table to another. I'll paste the code onto here and show you what's flagging on me (comment about the error within code). It probably seems a bit convoluted, but the UserProfileValue table is something that I TOTALLY wish Microsoft had second-guessed (it's from SharePoint Portal Server 2003)


SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


ALTER procedure profile_ImportUserProfileData

as

declare profile_curs cursor for
select UserProfileValue.RecordID, UserProfileValue.PropertyID, UserProfileValue.PropertyVal, PropertyList.PropertyName, PropertyList.DataType
from PropertyList
inner join UserProfileValue
on PropertyList.PropertyID = UserProfileValue.PropertyID
order by UserProfileValue.RecordId,
UserProfileValue.PropertyId

declare @RecordId int, @PropertyId int, @OldRecordId int
declare @PropertyVal sql_variant
declare @PropertyName nvarchar(20), @DataType nvarchar(20)
declare @table nvarchar(25)

set @table = 'UserProfileReportTable'

open profile_curs
fetch next from profile_curs into @RecordId, @PropertyId, @PropertyVal, @PropertyName, @DataType

if (@@fetch_status = -1)
begin
print 'End of table'
close profile_curs
deallocate profile_curs
return
end

while (@@fetch_status = 0)
begin
SET IDENTITY_INSERT UserProfileReportTable ON
insert UserProfileReportTable(RecordId)
values(@RecordId)
SET IDENTITY_INSERT UserProfileReportTable OFF

set @OldRecordId = @RecordId

fetch next from profile_curs into @RecordId, @PropertyId, @PropertyVal, @PropertyName, @DataType

if @DataType like 'nvarchar'
set @DataType = @DataType + '(20)'

while (@RecordId = @OldRecordId)
begin
declare @sql nvarchar(1000)
set @sql = 'update ' + @table
-- this next line is the one that's crapping out, saying "Incorrect syntax near @DataType"
set @sql = @sql + ' set ' + @PropertyName + ' = ' + convert(@DataType, @PropertyVal)
set @sql = @sql + ' where RecordId = ' + @RecordId
execute sp_executesql @sql
fetch next from profile_curs into @RecordId, @PropertyId, @PropertyVal, @PropertyName, @DataType
end
end

close profile_curs
deallocate profile_curs


GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO


I also tried cast(@PropertyVal as @DataType) but got the same results. I know it probably isn't the best idea to use a cursor, considering there are 3000+ records in UserProfileValue, but more than likely this procedure will only be run once, and I couldn't think of any better way to do it. Any help would be appreciated.

Thanks!

View 9 Replies View Related

Linked Server To MYSQL Using OLEDB Provider For MYSQL Cherry

Feb 12, 2007

Good Morning

Has anyone successfully used cherry's oledb provider for MYSQL to create a linked server from MS SQLserver 2005 to a Linux red hat platform running MYSQL.

I can not get it to work.

I've created a UDL which tests fine. it looks like this

[oledb]

; Everything after this line is an OLE DB initstring

Provider=OleMySql.MySqlSource.1;Persist Security Info=False;User ID=testuser;

Data Source=databridge;Location="";Mode=Read;Trace="""""""""""""""""""""""""""""";

Initial Catalog=riverford_rhdx_20060822

Can any on help me convert this to corrrect syntax for sql stored procedure

sp_addlinkedserver



I've tried this below but it does not work I just get an error saying it can not create an instance of OleMySql.MySqlSource.

I used SQL server management studio to create the linked server then just scripted this out below.

I seem to be missing the user ID, but don't know where to put it in.

EXEC master.dbo.sp_addlinkedserver @server = N'DATABRIDGE_OLEDB', @srvproduct=N'mysql', @provider=N'OleMySql.MySqlSource', @datasrc=N'databridge', @catalog=N'riverford_rhdx_20060822'

GO

EXEC master.dbo.sp_serveroption @server=N'DATABRIDGE_OLEDB', @optname=N'collation compatible', @optvalue=N'false'

GO

EXEC master.dbo.sp_serveroption @server=N'DATABRIDGE_OLEDB', @optname=N'data access', @optvalue=N'true'

GO

EXEC master.dbo.sp_serveroption @server=N'DATABRIDGE_OLEDB', @optname=N'dist', @optvalue=N'false'

GO

EXEC master.dbo.sp_serveroption @server=N'DATABRIDGE_OLEDB', @optname=N'pub', @optvalue=N'false'

GO

EXEC master.dbo.sp_serveroption @server=N'DATABRIDGE_OLEDB', @optname=N'rpc', @optvalue=N'false'

GO

EXEC master.dbo.sp_serveroption @server=N'DATABRIDGE_OLEDB', @optname=N'rpc out', @optvalue=N'false'

GO

EXEC master.dbo.sp_serveroption @server=N'DATABRIDGE_OLEDB', @optname=N'sub', @optvalue=N'false'

GO

EXEC master.dbo.sp_serveroption @server=N'DATABRIDGE_OLEDB', @optname=N'connect timeout', @optvalue=N'0'

GO

EXEC master.dbo.sp_serveroption @server=N'DATABRIDGE_OLEDB', @optname=N'collation name', @optvalue=null

GO

EXEC master.dbo.sp_serveroption @server=N'DATABRIDGE_OLEDB', @optname=N'lazy schema validation', @optvalue=N'false'

GO

EXEC master.dbo.sp_serveroption @server=N'DATABRIDGE_OLEDB', @optname=N'query timeout', @optvalue=N'0'

GO

EXEC master.dbo.sp_serveroption @server=N'DATABRIDGE_OLEDB', @optname=N'use remote collation', @optvalue=N'false'



Many Thanks



David Hills



View 7 Replies View Related

Equivalent To MySQL's Password() Function? (was MySQL To SQL Server And Password())

Mar 3, 2005

I have an internal Project Management and Scheduling app that I wrote internally for my company. It was written to use MySQL running on a Debian server, but I am going to move it to SQL Server 2000 and integrate it with our Accounting software. The part I am having trouble with is the user login portion. I previously used this:


PHP Code:




 $sql = "SELECT * FROM users WHERE username = "$username" AND user_password = password("$password")"; 






Apparently the password() function is not available when accessing SQL Server via ODBC. Is there an equivalent function I could use isntead so the passwords arent plaintext in the database? I only have 15 people using the system so a blank pwd reset wouldn't be too much trouble.

View 7 Replies View Related

Incorrect Syntax Near The Keyword CONVERT When The Syntax Is Correct - Why?

May 20, 2008

Why does the following call to a stored procedure get me this error:


Msg 156, Level 15, State 1, Line 1

Incorrect syntax near the keyword 'CONVERT'.




Code Snippet

EXECUTE OpenInvoiceItemSP_RAM CONVERT(DATETIME,'01-01-2008'), CONVERT(DATETIME,'04/30/2008') , 1,'81350'




The stored procedure accepts two datetime parameters, followed by an INT and a varchar(10) in that order.

I can't find anything wrong in the syntax for CONVERT or any nearby items.


Help me please. Thank you.

View 7 Replies View Related

Incorrect Syntax When There Appears To Be No Syntax Errors.

Dec 14, 2003

I keep receiving the following error whenever I try and call this function to update my database.

The code was working before, all I added was an extra field to update.

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'WHERE'


Public Sub MasterList_Update(sender As Object, e As DataListCommandEventArgs)

Dim strProjectName, txtProjectDescription, intProjectID, strProjectState as String
Dim intEstDuration, dtmCreationDate, strCreatedBy, strProjectLead, dtmEstCompletionDate as String

strProjectName = CType(e.Item.FindControl("txtProjectName"), TextBox).Text
txtProjectDescription = CType(e.Item.FindControl("txtProjDesc"), TextBox).Text
strProjectState = CType(e.Item.FindControl("txtStatus"), TextBox).Text
intEstDuration = CType(e.Item.FindControl("txtDuration"), TextBox).Text
dtmCreationDate = CType(e.Item.FindControl("txtCreation"),TextBox).Text
strCreatedBy = CType(e.Item.FindControl("txtCreatedBy"),TextBox).Text
strProjectLead = CType(e.Item.FindControl("txtLead"),TextBox).Text
dtmEstCompletionDate = CType(e.Item.FindControl("txtComDate"),TextBox).Text
intProjectID = CType(e.Item.FindControl("lblProjectID"), Label).Text

Dim strSQL As String
strSQL = "Update tblProject " _
& "Set strProjectName = @strProjectName, " _
& "txtProjectDescription = @txtProjectDescription, " _
& "strProjectState = @strProjectState, " _
& "intEstDuration = @intEstDuration, " _
& "dtmCreationDate = @dtmCreationDate, " _
& "strCreatedBy = @strCreatedBy, " _
& "strProjectLead = @strProjectLead, " _
& "dtmEstCompletionDate = @dtmEstCompletionDate, " _
& "WHERE intProjectID = @intProjectID"

Dim myConnection As New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("connectionstring"))
Dim cmdSQL As New SqlCommand(strSQL, myConnection)

cmdSQL.Parameters.Add(new SqlParameter("@strProjectName", SqlDbType.NVarChar, 40))
cmdSQL.Parameters("@strProjectName").Value = strProjectName
cmdSQL.Parameters.Add(new SqlParameter("@txtProjectDescription", SqlDbType.NVarChar, 30))
cmdSQL.Parameters("@txtProjectDescription").Value = txtProjectDescription
cmdSQL.Parameters.Add(new SqlParameter("@strProjectState", SqlDbType.NVarChar, 30))
cmdSQL.Parameters("@strProjectState").Value = strProjectState
cmdSQL.Parameters.Add(new SqlParameter("@intEstDuration", SqlDbType.NVarChar, 60))
cmdSQL.Parameters("@intEstDuration").Value = intEstDuration
cmdSQL.Parameters.Add(new SqlParameter("@dtmCreationDate", SqlDbType.NVarChar, 15))
cmdSQL.Parameters("@dtmCreationDate").Value = dtmCreationDate
cmdSQL.Parameters.Add(new SqlParameter("@strCreatedBy", SqlDbType.NVarChar, 10))
cmdSQL.Parameters("@strCreatedBy").Value = strCreatedBy
cmdSQL.Parameters.Add(new SqlParameter("@strProjectLead", SqlDbType.NVarChar, 15))
cmdSQL.Parameters("@strProjectLead").Value = strProjectLead
cmdSQL.Parameters.Add(new SqlParameter("@dtmEstCompletionDate", SqlDbType.NVarChar, 24))
cmdSQL.Parameters("@dtmEstCompletionDate").Value = dtmEstCompletionDate
cmdSQL.Parameters.Add(new SqlParameter("@intProjectID", SqlDbType.NChar, 5))
cmdSQL.Parameters("@intProjectID").Value = intProjectID

myConnection.Open()
cmdSQL.ExecuteNonQuery
myConnection.Close()

MasterList.EditItemIndex = -1
BindMasterList()


End Sub

Thankyou in advance.

View 3 Replies View Related

Which Is Faster? Conditional Within JOIN Syntax Or WHERE Syntax?

Mar 31, 2008

Forgive the noob question, but i'm still learning SQL everyday and was wondering which of the following is faster? I'm just gonna post parts of the SELECT statement that i've made changes to:

INNER JOIN Facilities f ON e.Facility = f.FacilityID AND f.Name = @FacilityName

OR

WHERE f.Name = @FacilityName


My question is whether or not the query runs faster if i put the condition within the JOIN line as opposed to putting in the WHERE line? Both ways seems to return the same results but the time difference between methods is staggering? Putting the condition within the JOIN line makes the query run about 3 times faster?

Again, forgive my lack of understanding, but could someone agree or disagree and give me the cliff-notes version of why or why not?

Thanks!

View 4 Replies View Related

Converting Rrom Access Syntax To Sql Syntax

Sep 23, 2007


Ok I am tying to convert access syntax to Sql syntax to put it in a stored procedure or view..
Here is the part that I need to convert:

SELECT [2007_hours].proj_name, [2007_hours].task_name, [2007_hours].Employee,
IIf(Mid([task_name],1,3)='PTO','PTO_Holiday',
IIf(Mid([task_name],1,7)='Holiday','PTO_Holiday',
IIf(Mid([proj_name],1,9) In ('9900-2831','9900-2788'),'II Internal',
IIf(Mid([proj_name],1,9)='9900-2787','Sales',
IIf(Mid([proj_name],1,9)='9910-2799','Sales',
IIf(Mid([proj_name],1,9)='9920-2791','Sales',

)
)
)
)
) AS timeType, Sum([2007_hours].Hours) AS SumOfHours
from................

how can you convert it to sql syntax

I need to have a nested If statment which I can't do in sql (in sql I have to have select and from Together for example ( I can't do this in sql):
select ID, FName, LName
if(SUBSTRING(FirstName, 1, 4)= 'Mike')
Begin
Replace(FirstNam,'Mike','MikeTest')
if(SUBSTRING(LastName, 1, 4)= 'Kong')
Begin
Replace(LastNam,'Kong,'KongTest')
if(SUBSTRING(Address, 1, 4)= '1245')
Begin
.........
End
End

end




Case Statement might be the solution but i could not do it.






Your input will be appreciated

Thank you

View 5 Replies View Related

One To One Relationships

May 29, 2007

 Ok, so I open up a book on beginning sql and it discusses relationships.There is something that appears wrong. I am not understanding how the book is describing the one to one relationship. In it's figure, it shows that the same agency can have two different artist id's. But according to it's definition of one to one list can be related from both tables.Can someone explain this further please?Thanks in advance.

View 3 Replies View Related

ADO.NET - Many-To-Many Relationships

Aug 8, 2007

How do you show many to many relationships in ASP.NET with datasources?
 I can retrieve the information from the database easily but I can't manage to save that information into a variable so that i can then call for only information in the M2M table related to the ID Key I want.  For example..1 <asp:Label ID="lblTestLabel" Text='<%# DataBinder.Eval(Container.DataItem, "title_id") %>' Runat="server" />
2
3 <script language="VB" runat="server">
4 sub Page_Load(sender as Object, e as EventArgs)
5 Dim lblTitleID As Label = Repeater1.FindControl("lblTestLabel")
6 Response.Write(lblTitleID.text)
7 End Sub
8 </script>

 When I try to run this script it dosn't work and I get the error:
 System.NullReferenceException: Object reference not set to an instance of an object.
For line 6 of the code above.  Is there a way to just retrieve information from a datasource without storing information into a label first?
PS: I use sqldatasource tags to retrieve information like:1 <asp:SqlDataSource ID="DataSet1" runat="server"
2 ConnectionString="Driver={MySQL ODBC 3.51 Driver};server=localhost;database=;user=;pwd=;option=3;"
3 ProviderName="System.Data.Odbc"
4 SelectCommand="Select * from titles order by title_id">
5 </asp:SqlDataSource>
 

View 2 Replies View Related

Many To Many && Other Relationships

Aug 10, 2007

Can someone help me sort something out. Suppose we have two tables in a database.One is named Person, and one is named Birthday. Is this a many to many relationshipor a 1 to many relationship?
Person has many birthdays. Example. Joe Schmoe has a birthday for every year of his life. birthday(7/11/1976) has many People (Many people have a birthday on 7/11/1976.

View 6 Replies View Related

Relationships...

Feb 2, 2004

Is there any easy way of getting all the relationships for the tables in aSQL server db? I've looked through Google and the Books online but I'm barely scratching the surface on the systables. I know I can go to each individual table and get the dependencies or even print out the diagram through Enterprise Manager but I really don't want to have to type out all the primary/foreign keys for 100+ tables. Any help on getting this data either through a 3rd party software or querying the systables would be great.

THT
DMW

View 5 Replies View Related

One-to-one Relationships

Mar 21, 2001

We have a table with approximately 150 colums and 2/3 of them are bit datatypes. We do not expect much activity on this table. Does it make sense to separate it into a few tables instead of 1 with one-to-one relationships? Will the join(s) significantly slow down our web application? Thank you

View 2 Replies View Related

Are Relationships Necessary

Aug 6, 2004

My hosting servers have "myLittleAdmin" installed. I am new to ms sql I have some experience with Access but I have never set up Relationships inside the database server. I have always just relied on my application logic to call the relations. What is the benefit to setting up relationships in sql, if any?

View 4 Replies View Related

One To Many Relationships

Nov 11, 2004

Is there a tool in Enterprise manager to list out the one to many & many relationships with a database?????:?:

View 4 Replies View Related

Relationships

Feb 1, 2007

Hey, I have SQL Sever Enterpise Manager. I am new at this company and I need to know the relationships between ALL the tables. Is there anywhere I can go to view all the primary keys and the relationships?

View 3 Replies View Related

Key Relationships

Jun 1, 2007

I am viewing tables in the ‘object explorer’- I can see the tables. If I open it up I can see columns, keys, constraints etc…

So I can see they key… can I tell which table/field the foreign key is connected to?

thanks

View 10 Replies View Related

Many To Many Relationships

Oct 17, 2007

Hello,

I have 3 tables. Posts, PostsTags and Tags.
This is a many to many relationship.

So PostsTags has the following columns:
PostId (PK) and TagId (PK)

I always did that way in SQL 2005.

In some examples I see PostsTags have 3 columns:
PostTagId(PK), PostId (FK), TagId (FK)

Should I use it this way, instead?

Thanks,
Miguel

View 8 Replies View Related

Relationships

Jul 13, 2006

Is it possible to have 2 different databases and create relationships inbetween the two? I am thinking about way down the road and the size of the databases and I believe that I need to split my data into multiple databases to keep from running into the size limitations.

Davids Learning

View 1 Replies View Related

One To One Relationships

May 29, 2007

Ok, so I open up a book on beginning sql and it discusses relationships.
There is something that appears wrong. I am not understanding how the book is describing the one to one relationship. In it's figure, it shows that the same agency can have two different artist id's. But according to it's definition of one to one list can be related from both tables.

http://foo.gearsector.com/foo/instr_scrns/oneToMany.gif


Can someone explain this further please?

Thanks in advance.

View 5 Replies View Related

RelationShips In SQL

Apr 1, 2008



How can I use with relationShips in SQl?
Tamir BLoch .

View 1 Replies View Related

Relationships Vs. No Relationships

Apr 3, 2007

Hello!



I have a really small database in terms of number of objects, but very big in terms of data (possibly millions of records). I always try to design my databases to be in the 3rd normal form (at least I hope they are!), but sometimes (for databases consisting of just a few tables) maintaining M:N relationships looks like an over-bloated approach to me... Let's see an actual example. I have a table like this:






Code SnippetCreate table [Airfares]
(
[OriginCity] Char(3) NOT NULL,
[DestCity] Char(3) NOT NULL,
[FareDate] Datetime Default getdate() NOT NULL,
[Price] Decimal(9,2) Default 0 NOT NULL,
[PriceChange] Decimal(9,2) Default 0 NOT NULL,
[Wrong] Bit Default 0 NOT NULL,
Primary Key ([OriginCity],[DestCity],[FareDate])
)
go







Now, at first there also was an Airline nvarchar(50) field, which stored the airline name. But now the client requested to store fares for a few airlines if it's the same price and city pair. This way we can have 3 airlines offering the same price on the same itinerary for example. So I added a dictionary table called Airlines:






Code SnippetCreate table [Airlines]
(
[AirlineCode] Char(2) NOT NULL,
[Name] Nvarchar(50) NOT NULL,
Primary Key ([AirlineCode])
)
go







Now, there are two things I can do. We are obviously dealing with the M:N relationship type here. I can either add another nvarchar column in the first table, like Airlines nvarchar(255) and store something like 'AA,AB,AC' there - those would be airline codes. OR I could do it the proper way and create a cross-reference table which will connect both Airfares and Airlines tables (this will store as many records as there are airlines for that particular itinerary, offerring the same price):






Code SnippetCreate table [AirfareAirlines]
(
[AirlineCode] Char(2) NOT NULL,
[OriginCity] Char(3) NOT NULL,
[DestCity] Char(3) NOT NULL,
[FareDate] Datetime Default getdate() NOT NULL,
Primary Key ([AirlineCode],[OriginCity],[DestCity],[FareDate])
)
go







But this is starting to look overly complicated, isn't it? The pros of this are I'm going to get real relationships, referential integrity, etc., but cons are more difficult code to query all this. What would you do? Do we really need referential integrity everywhere? Are there times when we're better not using relationships? I have seen many programmers skip referential integrity before, which always made me think they are missing something important in a Relational Database Management System.

View 13 Replies View Related

Relationships In SQL 2005?

Feb 13, 2008

Hi
How I can get to see the relationships, like in access, in sql 2005?
Thank,
K

View 1 Replies View Related

An Easy One: The Need For Relationships?

Mar 16, 2008

 Ok - I am still a bit weak on SQL.  My understanding of FK relationships in a database are to reinforce the data integrity - Correct?  For example, does it make sure that the id given for SiteID does indeed exists.  Can it link tables like JOIN in select statements? If not, is there any gains by creating them, such as performance?

View 1 Replies View Related

I've Never Been Good With Relationships

Feb 15, 2004

I'm having some trouble working out how to query some data. Rather than explain up front, here's some examples of what I want to achieve:

*******************************************************

I've got a structure which looks vaguely like this:

[ANCESTORS]

Grandparent
Parent
Child

If limit by grandparents, then I only get the lineage for that particular grandparent. I.e.:


SELECT *
FROM [ANCESTORS]
( some sort of joins here )
Where Grandparent.Name = 'Cybill'



This would return all of the children of 'Cybill' and their children. Now, if I use the following query:


SELECT *
FROM [ANCESTORS]
( some sort of joins here )
Where Child.Name = 'Jean'



This would return Jean's parents + the parents of Jean's parents (Jean's grandparents).

Likewise, if I enter:


SELECT *
FROM [ANCESTORS]
( some sort of joins here )
Where Parent.Name = 'Ron'



Then I would get Ron's parents and also his children.


*******************************************************

So, as you can see, at first it appears that I'm after a LEFT JOIN - meaning that the grandparents don't need to have child records to be returned, but, then it turns out that I need INNER JOINS - to limit grandparents when I choose children.

Can anybody see my dilemma here?

Mark-up ASP.net posts here
MarkItUp.com

View 10 Replies View Related

Relationships In MSDE - How Do I Do It?

Nov 27, 2005

Hi
I am using the Web Matrix Project to write a .NET
application.   I have set up a database using MSDE which I
accessed through the Web Matrix Project to start with.  I have now
found the Web Data Administrator which I use to backup my database and
help to transfer it to the Server where I hope to run this application
(if I ever get it finished!).

I need to set up some relationships between database tables but cannot
see a way to do this.  SQL Server Books on Line referes to
Enterprise Manager which I believe ships with the full MS SQL Server
package (and costs a package).  I am doing this on a
shoe-string.  Any ideas on how to do it?

Thanks in advance.

Mike

View 2 Replies View Related

Same Old Question About Relationships

Sep 11, 2003

I wanted to know that whether using relatioships betwenn tables improves performace for select queries?

what is the significance of using joins in queries after implementing relationships?

thanks

View 4 Replies View Related

Database Relationships

Aug 22, 2006

While playing about with SQL Server 2005 I am sure that I saw a tool to do relationships the same was as in access - however now I can't find it.

Am I seeeing things or does this really exist?

View 2 Replies View Related

Finding Relationships

Sep 23, 2005

Hi, sorry if this comes across as a stupid question, but i'm new to SQL. I have had a look on Google and on these forums but not found the answer..
I am running MS SQL 7 with a database containing around 130 tables.. i want to know if there is a query/command that i can type that will look through all the tables and tell me which ones reference a specified table (through it's key). Hope this makes sense! i've looked at some of the stored procedures but not found any that give me anything useful.

EDIT: Just so you are aware, i did not create this database, hence why i am not aware of the relationships myself, i have only just started working on it.

Thanks
Steve

View 2 Replies View Related

Relationships And Index's

Dec 14, 2006

I'm upgrading my sites forum to a newer version. I've tried, unsuccessfully so far, to transfer member details, threads and posts to the new format. I say unsuccessfully but I have made it work once by deleting the Index's and Relationships on tables and re-entering them after transfer but his ended up screwing with the regestration of new members.
Before I become more frustrated than I already am, could I run something by you guys with the experience you have.

If I delete the Rels and Indx's again, then move all my tables over and then run this code through my browser, will the Indexs and Relationships find their way back to the right place?

Part 1


Code:

strSQL = "CREATE INDEX [Ban_ID] ON [" & strDBO & "].[" & strDbTable & "BanList]([Ban_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE UNIQUE INDEX [Cat_ID] ON [" & strDBO & "].[" & strDbTable & "Category]([Cat_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [" & strDbTable & "Group_ID] ON [" & strDBO & "].[" & strDbTable & "Group]([Group_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Poll_ID] ON [" & strDBO & "].[" & strDbTable & "Poll]([Poll_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Author_ID] ON [" & strDBO & "].[" & strDbTable & "Author]([Author_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Group_ID] ON [" & strDBO & "].[" & strDbTable & "Author]([Group_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)


strSQL = "CREATE INDEX [" & strDbTable & "Group" & strDbTable & "Author] ON [" & strDBO & "].[" & strDbTable & "Author]([Group_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE UNIQUE INDEX [User_code] ON [" & strDBO & "].[" & strDbTable & "Author]([User_code]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE UNIQUE INDEX [Username] ON [" & strDBO & "].[" & strDbTable & "Author]([Username]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Cat_ID] ON [" & strDBO & "].[" & strDbTable & "Forum]([Cat_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Sub_ID] ON [" & strDBO & "].[" & strDbTable & "Forum]([Sub_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Last_post_author_ID] ON [" & strDBO & "].[" & strDbTable & "Forum]([Last_post_author_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)


strSQL = "CREATE INDEX [" & strDbTable & "Categories" & strDbTable & "Forum] ON [" & strDBO & "].[" & strDbTable & "Forum]([Cat_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Choice_ID] ON [" & strDBO & "].[" & strDbTable & "PollChoice]([Choice_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Poll_ID] ON [" & strDBO & "].[" & strDbTable & "PollChoice]([Poll_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [" & strDbTable & "Polls" & strDbTable & "PollChoice] ON [" & strDBO & "].[" & strDbTable & "PollChoice]([Poll_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Address_ID] ON [" & strDBO & "].[" & strDbTable & "BuddyList]([Address_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Author_ID] ON [" & strDBO & "].[" & strDbTable & "BuddyList]([Buddy_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Buddy_ID] ON [" & strDBO & "].[" & strDbTable & "BuddyList]([Author_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [" & strDbTable & "Author" & strDbTable & "BuddyList] ON [" & strDBO & "].[" & strDbTable & "BuddyList]([Buddy_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Author_ID] ON [" & strDBO & "].[" & strDbTable & "EmailNotify]([Author_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Forum_ID] ON [" & strDBO & "].[" & strDbTable & "EmailNotify]([Forum_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [" & strDbTable & "Author" & strDbTable & "TopicWatch] ON [" & strDBO & "].[" & strDbTable & "EmailNotify]([Author_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Toipc_ID] ON [" & strDBO & "].[" & strDbTable & "EmailNotify]([Topic_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Watch_ID] ON [" & strDBO & "].[" & strDbTable & "EmailNotify]([Watch_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Auhor_ID] ON [" & strDBO & "].[" & strDbTable & "PMMessage]([Author_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [From_ID] ON [" & strDBO & "].[" & strDbTable & "PMMessage]([From_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Message_ID] ON [" & strDBO & "].[" & strDbTable & "PMMessage]([PM_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [" & strDbTable & "Author" & strDbTable & "PMMessage] ON [" & strDBO & "].[" & strDbTable & "PMMessage]([From_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [" & strDbTable & "Forum_ID] ON [" & strDBO & "].[" & strDbTable & "Permissions]([Forum_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [" & strDbTable & "Forum" & strDbTable & "Permissions] ON [" & strDBO & "].[" & strDbTable & "Permissions]([Forum_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [" & strDbTable & "Group_ID] ON [" & strDBO & "].[" & strDbTable & "Permissions]([Group_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Forum_ID] ON [" & strDBO & "].[" & strDbTable & "Topic]([Forum_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Poll_ID] ON [" & strDBO & "].[" & strDbTable & "Topic]([Poll_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Start_Thread_ID] ON [" & strDBO & "].[" & strDbTable & "Topic]([Start_Thread_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Last_Thread_ID] ON [" & strDBO & "].[" & strDbTable & "Topic]([Last_Thread_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Moved_ID] ON [" & strDBO & "].[" & strDbTable & "Topic]([Moved_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [" & strDbTable & "Forum" & strDbTable & "Topic] ON [" & strDBO & "].[" & strDbTable & "Topic]([Forum_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Topic_ID] ON [" & strDBO & "].[" & strDbTable & "Topic]([Topic_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Message_date] ON [" & strDBO & "].[" & strDbTable & "Thread]([Message_date]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Message_ID] ON [" & strDBO & "].[" & strDbTable & "Thread]([Thread_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [" & strDbTable & "Author" & strDbTable & "Thread] ON [" & strDBO & "].[" & strDbTable & "Thread]([Author_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [" & strDbTable & "Topic" & strDbTable & "Thread] ON [" & strDBO & "].[" & strDbTable & "Thread]([Topic_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Topic_ID] ON [" & strDBO & "].[" & strDbTable & "Thread]([Topic_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Guest_ID] ON [" & strDBO & "].[" & strDbTable & "GuestName]([Guest_ID]) ON [PRIMARY] "

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [" & strDbTable & "Thread" & strDbTable & "GuestName] ON [" & strDBO & "].[" & strDbTable & "GuestName]([Thread_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE INDEX [Thread_ID] ON [" & strDBO & "].[" & strDbTable & "GuestName]([Thread_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

strSQL = "CREATE UNIQUE INDEX [Session_ID] ON [" & strDBO & "].[" & strDbTable & "Session]([Session_ID]) ON [PRIMARY]"

'Write to the database
adoCon.Execute(strSQL)

'If an error has occured write an error to the page
If Err.Number <> 0 Then
Response.Write("<br />Error Creating one or more Indexs <br />" & Err.description & "<br /><br />")

'Reset error object
Err.Number = 0

'Set the error boolean to True
blnErrorOccured = True
End If

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved