Unsolved sql database
-
HOW TO GENERATE UNIQUE ID(CHARACTER + NUMBER) IN SQL SERVER qt create table with UNIQUE ID and insert UNIQUE ID.
-
@satyanarayana143 said in sql database:
qt create table
Actually you create a table using "CREATE TABLE" SQL statement.
Can you explain better what you are doing?Also, please do not write all upper case...
-
create table customer(
ID int IDENTITY(1,1) NOT NULL,
PreFix varchar(64) NOT NULL,
CustomerNo AS(PreFix+RIGHT('0000000' +CAST(ID AS varchar(8)),8))PERSISTED,
CustomerName varchar(64)
);INSERT INTO customer(PreFix,CustomerName)Values('SID','test')
INSERT INTO customer(PreFix,CustomerName)Values('SID','test1')
INSERT INTO customer(PreFix,CustomerName)Values('SID','test2')output:
SID00000001
SID00000002
SID00000003this like in qt this code in .net in qt i required i am trying create table in qt like this table is not creating
PreFix varchar(64) NOT NULL,
CustomerNo AS(PreFix+RIGHT('0000000' +CAST(ID AS varchar(8)),8))PERSISTED,if (m_Bocdb.open())
{
QSqlQuery query(m_Bocdb);
if (query.exec(CREATE TABLE IF NOT EXISTS customer("ID int IDENTITY(1,1) NOT NULL,"
" PreFix varchar(64) NOT NULL,"
" CustomerNo AS(PreFix+RIGHT('0000000' +CAST(ID AS varchar(8)),8))PERSISTED,"
" CustomerName varchar(64)))
{
qDebug() << "customer Table created" ;
}
else
{
qDebug() << "customer Table not created" ;
}
}i am trying to create table like .net code i am getting error
customer Table not created"
-
@satyanarayana143 said in sql database:
i am getting error
What error please?
Please print out what https://doc.qt.io/qt-5/qsqlquery.html#lastError returns... -
create Error: "near "AS": syntax error Unable to execute statement"
-
@satyanarayana143 So, your query is invalid, nothing Qt related.
Please post what https://doc.qt.io/qt-5/qsqlquery.html#lastQuery outputs after executing the query.