sql server - SQL Insert with data from multiple tables -


I have four tables: messages, messagecents, messagestats, and message levels. Message content, messaging, and messages are all just three fields: Identity (primary key), code and description message shows these three areas and they have some other data fields, including the identity (primary key) Message text and order are included. Identity fields are auto-enclosed fields.

I now need to write SQL script to add some default data to all slabs. I have problems, I need to create a script that will be sent to a customer who will then execute this script. I can not write a little more intelligent code to make the full update. And while there are just simple insertion statements in three tables, this is a message table, which gives me some extra headaches.

I can not remove any index and I can not assume that the count for 1 for the primary key starts counting.

So, for example, it has some data:

  Include message category (code) values ​​('CAT1'); Enter the value (code) in the message position ('Status 101'); Include message level (code) values ​​('Level 101');  

And messages will need something like this:

  Enter the message (category, status, level, message text, order) values ​​( Selection identification from MessageCategory where code = 'Cat 101'), (Identify the selection from the message status where code = 'Status 01'), (Identification of code from code code where code = 'Level 101'), 'Just a few messages', 1 );  

This will not work, though. So, what's the trick to do this work? (Even keeping the code readable ...)

Unfortunately, I do not have access to other databases. I can test it, but once it starts working, And-Prayer- This works ...

The above will work for SQL Server Note that both identity and commands are reserved T-SQL keywords and column names Should not be used for Also keep in mind that sub-questions should not return more than one line to do this work, to ensure that I have included the TOP 1 statement.

The next thing to note is that the column nickname ( AS category etc.) is not strictly necessary. I add them to readability, especially when the SELECT list is high.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -