Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
If you have a table created in SQL with the first column being the primary key and you alter/set certain rows with new data, then is this the same thing as updating a .h file in C++?

My understanding --> In C++, this avoids the need to manually update (as an example) each variable/function which contains the public variable/function located in different .cpp files?

I am looking more for input to expand on this, as I am learning SQL and try to translate my understanding of SQL to C++.

What I have tried:

I did a search on several different search engines, but the results were either related specifically to SQL or C++ or how to use C++ with SQL.
Posted
Updated 17-May-22 21:52pm
Comments
RedDk 17-May-22 20:06pm    
What interfaces to SQL and C++ are you using?

SQL is a method for accessing a database. The tables in the database contain data. While it's true that you might need to use SQL to get data out of a given database, it's not necessarily a requirement. A given database engine could support SQL, XQuery, and a C++ API. Think of this as similar to reading a text file which you could do in Python, C++, C# etc.

Adding or modifying data in a table is more like changing data in a flat file, than modifying your C++ code. When you update data in the database, you're doing just that. You read a row from the database and get the field "price" as 5.99. An update to the database is made and the next time you read the same row, the "price" field is 6.15.

Be aware that just because you describe a table as
SQL
CREATE TABLE mytable (
    id integer PRIMARY KEY,
    first_name VARCHAR(30),
    last_name  VARCHR(30)
    birthday   DATE,
    address    VARCHAR(100) );

does not mean that that's the order that the database will store the columns in the table. While almost every database does so, it's not a requirement and some database out there mighr re-order the columns to optimize for space. So you're not guaranteed that doing select(*) will get you the columns in the expected order. In you code you should always specify the columns you want to retrieve in the order you want them.
 
Share this answer
 
No they are completely different. A C++ .h file is just a collection of lines of text with no predefined structure. The content is processed by the compiler pre-processor and then the compiler proper to create a machine code object file.

SQL is a query language used to access structured information held in a database. There is no correlation between the two.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900