Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7607065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:34:03+00:00 2026-05-31T00:34:03+00:00

I have a number of tables I need to convert from mySQL to SQL

  • 0

I have a number of tables I need to convert from mySQL to SQL Server.

An Example of a mySQL Table is

CREATE TABLE `required_items` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'Unique Barcode ID',
`fk_load_id` INT( 11 ) NOT NULL COMMENT 'Load ID', 
`barcode` VARCHAR( 255 ) NOT NULL COMMENT 'Barcode Value',
`description` VARCHAR( 255 ) NULL DEFAULT NULL COMMENT 'Barcode Description',
`created` TIMESTAMP NULL DEFAULT NULL COMMENT 'Creation Timestamp',
`modified` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Modified Timestamp',
FOREIGN KEY (`fk_load_id`) REFERENCES `loads`(`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = InnoDB CHARACTER SET ascii COLLATE ascii_general_ci COMMENT = 'Contains Required Items for the Load';

And a trigger to update the created date

CREATE TRIGGER required_items_before_insert_created_date BEFORE INSERT ON `required_items`
FOR EACH ROW
BEGIN
  SET NEW.created = CURRENT_TIMESTAMP;
END

Now I need to create tables similar to this in SQL Server. There seems to be a lot of different data types available so I am unsure which to use.

  • What data type should I use to the primary key column
    (uniqueidentifier, bigint, int)?
  • What should I use for the timestamps
    (timestamp, datatime, datetime2(7))?
  • How should I enforce the created
    and modified timestamps (currently I am using triggers)?
  • How can I enforce foreign key constraints.
  • Should I be using Varchar(255) in SQL Server? (Maybe Text, Varchar(MAX) is better)

I am using Visual Studio 2010 to create the tables.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:34:05+00:00Added an answer on May 31, 2026 at 12:34 am

    First of all, you can probably use PHPMyAdmin (or something similar) to script out the table creation process to SQL Server. You can take a look at what is automatically created for you to get an idea of what you should be using. After that, you should take a look at SSMS (SQL Server Management Studio) over Visual Studio 2010. Tweaking the tables that your script will create will be easier in SSMS – in fact, most database development tasks will be easier in SSMS.

    What data type should I use to the primary key column (uniqueidentifier, bigint, int)?
    Depending on how many records you plan to have in your table, use int, or bigint. There are problems with uniqueidentfiers that you will probably want to avoid. INT vs Unique-Identifier for ID field in database

    What should I use for the timestamps (timestamp, datatime, datetime2(7))?
    timestamps are different in SQL Server than in MySQL. Despite the name, a timestamp is an incrementing number that is used as a mechanism to version rows. http://msdn.microsoft.com/en-us/library/ms182776%28v=sql.90%29.aspx . In short though, datetime is probably your best bet for compatibility purposes.

    How should I enforce the created and modified timestamps (currently I am using triggers)?
    See above. Also, the SQL Server version of a “Timestamp” is automatically updated by the DBMS. If you need a timestamp similar to your MySQL version, you can use a trigger to do that (but that is generally frowned upon…kind of dogmatic really).

    How can I enforce foreign key constraints.
    You should treat them as you would using innoDB. See this article for examples of creating foreign key constraints http://blog.sqlauthority.com/2008/09/08/sql-server-%E2%80%93-2008-creating-primary-key-foreign-key-and-default-constraint/

    Should I be using Varchar(255) in SQL Server? (Maybe Text, Varchar(MAX) is better)
    That depends on the data you plan to store in the field. Varchar max is equivalent to varchar(8000) and if you don’t need varchar(255), you can always set it to a lower value like varchar(50). Using a field size that is too large has performance implications. One thing to note is that if you plan to support unicode (multilingual) data in your field, use nvarchar or nchar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a number of Tables setup in SQl Server i have transferred all
Suppose that we have following tables create table Employee( 2 EMPNO NUMBER(3), 3 ENAME
I have an HTML table with a large number of rows, and I need
I have one table TABLE_SUBJECT which contain a number of subjects. I need to
I have a number of LINQ to SQL tables with the same fields (
I have a number of manually written scripts (.sql) for tables, views and stored
I have to convert a set of C# classes (class library) to SQL tables
I have a common field in a database table on SQL Server 2008. The
I have a number of tables in an eclipse SWT application. They are Table/TableViewer
I have a fairly complex SQL query, where we'll need to return a number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.