Skip to content
Code Project
CODE PROJECT For Those Who Code

Database

Discussions on database access, SQL, and ADO

This category can be followed from the open social web via the handle database@forum.codeproject.com

17.1k Topics 61.8k Posts
  • Query to Test for SA [modified]

    question database
    6
    0 Votes
    6 Posts
    1 Views
    L
    :laugh: Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
  • SQL Server Connect Test

    database question sql-server sysadmin security
    2
    0 Votes
    2 Posts
    0 Views
    D
    Yes, you can test your credentials. Execute a command like select count(*) from myTable and redirect the output to a file, then parse the file for the expected results and if there is no error you have validated that your username/password combination is correct. Do this through osql.
  • stored procedure for restore .bak file

    database help
    2
    0 Votes
    2 Posts
    0 Views
    V
    i have this set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go -- Restore a backed up database -- Given: the filename and path where the backedup database file is located and the name of the database to restore it as -- The entry will be restored and a row placed into oDirect.dbo.tbl_dbref - which keeps track of the databases -- The users for the database must also be restored! ALTER PROCEDURE [dbo].[sp_RestoreDatabase] @dbname char(32), -- the database name to restore as @filename char(64), @path char(256) -- the location of the backuped up database file (on the SQL Server) AS set nocount on declare @sql nvarchar(3000) execute('sp_ClearDatabaseConnections ' + @dbname) -- Restore the database select @sql = ' RESTORE DATABASE ' + ltrim(rtrim( @dbname )) + ' FROM DISK = ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @filename )) + ''' ' select @sql = ltrim(rtrim(@sql)) + ' WITH ' select @sql = ltrim(rtrim(@sql)) + ' MOVE ''' + 'TNGoedit_Data' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '.mdf' + ''' , ' -- logical file name to physical name select @sql = ltrim(rtrim(@sql)) + ' MOVE ''' + 'TNGoedit_Log' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '_log.ldf' + ''' ' -- logical file name to physical name select @sql = ltrim(rtrim(@sql)) + ' ,REPLACE,RECOVERY;' --select @sql = ltrim(rtrim(@sql)) + ' MOVE ''' + ltrim(rtrim(@dbname)) + '_Data' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '.mdf' + ''' , ' -- logical file name to physical name --select @sql = ltrim(rtrim(@sql)) + ' MOVE ''' + ltrim(rtrim(@dbname)) + '_Log' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '_log.ldf' + ''' ' -- logical file name to physical name print @sql execute ( @sql ) -- Was the command successful or was there a problem if ( (select @@Error) = 0 ) begin -- Put an entry into oDirect.dbo.tbl_dbRef -- execute ( 'sp_DataSet_Save ''' + @xml + ''' ' ) -- TODO: restore the users select 'Restore Successful' [Result] end else begin select 'Restore Unsuccessful' [Result] end You can Simply change it to BAK file Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/
  • 0 Votes
    2 Posts
    0 Views
    M
    This is a really dumb idea, doubling your transaction cost to support a summary table that you query how often. Putting in a trigger (triggers are evil, like cursors) for such a trivial, non essential operation is not good. Create a view or a stored proc to get the information when and if you need it. A trigger is exactly like a proc except it can reference the inserted/updated record it is called from. Read BOL for some examples. Never underestimate the power of human stupidity RAH
  • 0 Votes
    2 Posts
    0 Views
    J
    If it's properly done you can't get the unencrypted passwords from the database. The normal procedure is that you encrypt the supplied password with the same algorithm as was used when storing it in the database, and then compare.
  • Need help with DATEDIFF function

    question css help
    3
    0 Votes
    3 Posts
    0 Views
    J
    Thank you Ashfield, I'll test it out later and come back if I still have an issue.
  • Need help with creating dynamic SQL statement

    database help question
    2
    0 Votes
    2 Posts
    0 Views
    M
    If it works then you can only improve the structure of the query otherwise it is an exercise in string concatenation. If the where clause is the only dynamic piece and the elements are known you can use something like Where (IsNull(@AttrID, -1) = -1 OR AttrID = @AttrID) where the default value is null or -1. Caveat, too many of these (about 6 IIRC) MAY affect the query performance I believe. I use it all the time and have had up to 8 elements in the where clause and it worked fine. The only benefit is it is not dynamic, not a huge issue! Never underestimate the power of human stupidity RAH
  • 0 Votes
    2 Posts
    0 Views
    J
    I have the same problem. Did you found a solution?
  • cannot excute script

    help apache database sql-server sysadmin
    5
    0 Votes
    5 Posts
    0 Views
    J
    it can't be low powered machine(4GB RAM, 2.8GHz Duo Core) i finally exported it to csv and ported it excel. i had all data in there so just wrote some sql statemet to import the data..into my tables. the whole dbase is in apache derby and i need all of them in a platform i am comfortable with. thanks
  • Distributed DB

    database tutorial question csharp sales
    4
    0 Votes
    4 Posts
    0 Views
    L
    The NHibernate team has a working demo[^]. 'njoy :) I are Troll :suss:
  • MSSQL USE

    c++ help database sql-server question
    3
    0 Votes
    3 Posts
    0 Views
    M
    if i use use master And i want to create some table in different database then what i will do?
  • Table rows vs. comma separated

    question database sql-server visual-studio help
    7
    0 Votes
    7 Posts
    0 Views
    G
    The database schema is created in such a way that data that needs complex queries are placed in their own tables. The table in question is a 2 column composite key table. From what I've gathered here, the engine should have no trouble doing simple queries against several million rows. Thanks for the clarification though. Does any of you by chance have any good articles on database optimization and inner workings of RDBMS?
  • 0 Votes
    27 Posts
    0 Views
    R
    Yup, much easier! :-D "A Journey of a Thousand Rest Stops Begins with a Single Movement"
  • How to work with folder and File ?

    csharp database sql-server sysadmin
    8
    0 Votes
    8 Posts
    0 Views
    N
    To be honest, though I proposed a solution, but I agree with you. If the person is using .net, it is better to go ahead with SMO. In any other technology, there must be some option to go ahead. Niladri Biswas
  • Format function in SQL Server

    database sql-server sysadmin help
    3
    0 Votes
    3 Posts
    0 Views
    B
    Hi,try this SELECT convert(varchar(10),CONVERT(DATETIME,'2009-12-10 10:11:00'),120) I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
  • ssis script component

    database sql-server c++ com sysadmin
    2
    0 Votes
    2 Posts
    0 Views
    U
    Hi, We have event-based data currently being logged in relational database structures. For various reasons this data need to be stored elsewhere, possibly on our existing PI historian database. We need to ascertain whether PI can relatively easily store this type of event based data, and ultimately produce reports using RT Web Parts, also relatively easily. If not, we would rather log it in a SQL Server database. 1. This data are obtained via a SSIS package from flat files and stored in a SQL server database. 2. Currently we have around 550 event based jobs running parallel typically on a daily basis. 3. This constitutes in approximately 100 000 records every 5 minutes being logged. That’s more or less 350 records every single second. 4. These events are currently sorted on a BigInt type incremented number from low to high. Can PI log values at a micro sub second level so that the values can be displayed in the correct order it was logged? Or are there some other way to do this? 5. Note that EvTime only saves at second level. EvSeqNo is necessary here to sort the data sequentially, as many records are logged per second. 6. Can Pi handle this huge influx of data? 7. A sequence can constitute a various number of events, from starting that sequence by starting a job by an operator, holding or diverting it. Starting, holding, diverting and so forth constitutes an event. There are various other events as well 8. A job can start another job as well. 9. EvJob, EvLevel, EvLabel, EvKey,EvText, EvSeqNo are all stored in separate database columns. Must this be concatenated into one delimited string or is there an easier way to store the data in PI? 10. EVJob should typically the tag name. However when a job is started by an operator EVJOb can be something like :Citect which means that the actual job being started must be retrieved from the EvText string. 11. Once all this data is being logged, can it easily be retrieved to display in reports using RT Web Parts?
  • 0 Votes
    4 Posts
    0 Views
    M
    I concur. This is NOT the place for a trigger. I only use triggers to store 1)disposable, 2)derived and 3)complex data used for reporting or searching. Must meet all 3 criteria. But to answer the question- UPDATE Demo Set BeModified = 1 WHERE ID IN (SELECT ID FROM inserted) OR UPDATE Demo Set BeModified = 1 FROM Demo INNER JOIN inserted ON Demo.ID = inserted.ID This is assuming sql server. The "inserted" table is a virtual table which contains all of the fields and values from the insert, update or delete that fired the trigger. You might think that only a record at a time is updated but in fact since it is possible to update multiple records at the same time, this may NOT be what you want. But thats what you get with triggers. If you ever have to update all of the records in that table, BeModified will be set to 1 for all. Be warned.
  • 0 Votes
    3 Posts
    0 Views
    D
    I am using an application created by a vendor where they use XML tables to store "custom" grid type data that we can define. For example: Given an employee record, we want to store safety qualifications and their expiration dates. Something like "CPR", "QualifiedOn", "ExpiresOn" What the vendor has done is created an additional table called, "EMP_MATRIXDATA" KEYID MATRIX_NAME (name we give the custom grid, like "SafetyTests" MAXTRIX_DATA (datatype is an XML document) With this type of design, you can provide a very flexible method for storing all kinds of grid data. You can even build in an XSD column into the table which would hold the schema of the associated table. You will pay a price for searchability, but do some research on the topic of storing XML data in SQL server and you will be suprised how good it really is. Good luck. :cool: :thumbsup:
  • 0 Votes
    5 Posts
    0 Views
    D
    Mycroft Holmes wrote: Doing that is akin to sticking your finger in the power point, may not kill you but your fingers gonna sting for a while. :laugh: Never tried this. Mycroft Holmes wrote: So did the extra set of brackets work? Yes it did. 50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
  • How to group data which not the same ?

    help tutorial csharp question
    6
    0 Votes
    6 Posts
    0 Views
    L
    Hi, you can use SELECT DISTINCT[^] and ORDERBY to get an ordered list of all different company names present. you can't find the "shortest" names as in your example, it would only give "Comx", not what you said it would. :) Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages