I'm a complete beginner to SQLite. I'm trying to open a database called CollegeData. CollegeData.sql is in the same directory as sqlite3.exe.In sqlite3 I'm typing in:
_.read CollegeData.sql_
Then I get an error for every line:
_near line #no.: no such table: #table name_
If I try:
_.open CollegeData.sql_
and then run a query, I get info that CollegeData is not a database.
Please help!
Related
I just started learning SQL. I downloaded the mdf file and moved it to the SQL folder. The course instructor told us to enter these commands to display the finished database. It throws me the error that my file doesn't exist even though I entered the correct path name. What is the matter? Sorry if the question is too stupid I just started learning.
Here is some pictures of the problem.
Your .mdf file should be in this path:
FILENAME = N'C:\MSSQL\SQLData\<database name>.mdf'
To attach a database there are some ways to do it like :
The one i've showed you:
USE [master]
GO
create database <DatabaseName> ON
(name='LogicalName of the Data file', FileName='Data File Name'),
(name='LogicalName of the Log file', FileName='Log File Name')
FOR ATTACH;
Or this way:
USE [master]
GO
EXEC sp_attach_db #dbname = N'DatabaseName',
#filename1 = '<Location of the database file>',
#filename2 = '<Location of the Log file>';
Illuminate \ Database \ QueryException (42S02)
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'influencingquotes.posts' doesn't exist (SQL: select count(*) as aggregate from posts where quote_title = gtav hyhui)
I am not sure why this Database\QueryException is occurring :(
The Error says that the posts table is missing, maybe you forget to run:
php artisan migrate
1.If in database you couldn't find posts table
Then you need to try to find migration file for it
which for laravel 5 located in project_root_dir\database\migrations
Then via command line
php artisan migrate
2.If in database exist table, but name is wrong , for example name is post
In post model you need to specify table name
protected $table = 'post';
If it doesn't help, you need to write us
1.what you see in database, which tables or views exists there
2.What files you see in project_root_dir\database\migrations directory.
I am new to database. I am trying to create a database and table in it.
but unable to save and open again after exiting from sqlite.
I am using sqlite3 3.6.20 on centOS, when i will enter following command
.save ex1.db or .open ex1.db
it will print following error message.
Error: unknown command or invalid arguments: "save". Enter ".help" for help
Error: unknown command or invalid arguments: "open". Enter ".help" for help
and when Print .help
it wont show any command related to save and open existing database.
thanks in advance.
I am trying to create a database and table in it. but unable to save and open again after exiting from sqlite.
You don't need to save. Each transaction writes to disk. (More or less.)
To create the database "test.sl3", you can do this. (From the command line. Programs work about the same way.)
$ sqlite3 test.sl3
SQLite version 3.8.7.2 2014-11-18 20:57:56
Enter ".help" for usage hints.
sqlite> create table test (test_id integer primary key);
sqlite> insert into test values (1);
sqlite> select * from test;
1
.quit
No .save. Now load the database again.
$ sqlite3 test.sl3
SQLite version 3.8.7.2 2014-11-18 20:57:56
Enter ".help" for usage hints.
sqlite> select * from test;
1
The data is still there.
You're supposed to provide a filename as an argument for the .save command, e.g.:
sqlite> .save ex1.db
docs: http://www.sqlite.org/cli.html
as Mike pointed out in his answer, you should provide a file name to put the database in.
If you did a lot of work and you did not provide a file name up front and you work in a version in which the .save command is not yet available (you quote that sqlite3 3.6.20 does not know it and I also do not see it in sqlite3 version 3.8.2) you can use the .backup command
sqlite> .help
[...]
.backup ?DB? FILE Backup DB (default "main") to FILE
$ sqlite3
[...]
sqlite> create table mytable ( column1 text, column2 integer );
sqlite> insert into mytable values ( 'ENTRY1', 1 );
sqlite> insert into mytable values ( 'ENTRY2', 2 );
sqlite> .backup main temp.db
sqlite> .quit
$ sqlite3 temp.db
[...]
sqlite> .schema
CREATE TABLE mytable ( column1 text, column2 integer );
sqlite> select * from mytable;
column1 column2
---------- ----------
ENTRY1 1
ENTRY2 2
Use Sqlite3 ex1.db to open your database. After that, all queries will take effect in your DB.
Maybe try using an absolute path instead of a relative path.
I am in VS Code using the SQLite extension by alexcvzz.
When I use a relative path, I get an error.
CREATE TABLE test (id INTEGER, name TEXT);
INSERT INTO test (id, name) VALUES (1, "Hello");
.save ex1.db
When I use an absolute path, it works.
CREATE TABLE test (id INTEGER, name TEXT);
INSERT INTO test (id, name) VALUES (1, "Hello");
.save /Users/zacharyargentin/databases/ex1.db
Note: In the VS Code extension you have to choose a database before you run the query, so I chose the :memory: database, which is the default in-memory database. This database deletes itself as soon as you close the connection (so if you want to keep it, you have to save it like I did in the example above).
I'm trying to check if table exists and if not, then I want to create it. But I'm still getting this error:
Error report -
ORA-06550: řádka 30, sloupec 28:
PL/SQL: ORA-00942: tabulka nebo pohled neexistuje
ORA-06550: řádka 30, sloupec 3:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
My code is:
SELECT COUNT(*) into cnt FROM dba_tables WHERE owner = 'CENTRUMADMIN' and table_name = 'AUD$_BACKUP';
DBMS_OUTPUT.PUT_LINE(cnt);
IF (cnt <= 0) THEN
EXECUTE IMMEDIATE 'CREATE TABLE CENTRUMADMIN.AUD$_BACKUP AS select * from SYS.AUD$ where 1=2';
DBMS_OUTPUT.PUT_LINE('Vytvorena tabulka AUD$_BACKUP ve shematu CENTRUMADMIN:');
END IF;
This code is inside my procedure for cleaning audit trail.
Can anyone pls help? Thanks in advance!
As I read in your comments you said you get the error only when the table AUD$_BACKUP does not exist.
which means you get you error here:
EXECUTE IMMEDIATE 'CREATE TABLE CENTRUMADMIN.AUD$_BACKUP AS select * from SYS.AUD$ where 1=2';
I guess you just dont have permissions for sys.AUD$ in you schema.
please notice that PL/SQL code can use role privileges. which means, even if you have "dba" role on your schema, it wont work. so you should run the following grant command:
Alter user myuser select on sys.AUD$
good luck.
I'm trying to run the following UPDATE query from a python script (note I've removed the database info):
print 'Connecting to db for update query...'
db = pyodbc.connect('DRIVER={FreeTDS};SERVER=<removed>;DATABASE=<removed>;UID=<removed>;PWD=<removed>')
cursor = db.cursor()
print ' Executing SQL queries...'
for i in range(len(data)):
sql = '''
UPDATE product.sanction
SET action_summary = '{action_summary}'
WHERE sanction_id = {sanction_id};
'''.format(sanction_id=data[i][0], action_summary=data[i][1])
cursor.execute(sql)
cursor.close()
db.commit()
db.close()
However, it hangs indefinitely, no error.
I'm new to pyodbc, but it should be setup correctly considering I'm having no problems performing SELECT queries. I did have to call CAST for SELECT queries (I've cast sanction_id AS INT [int identity on the database] and action_summary AS TEXT [nvarchar on the database]) to properly populate data, so perhaps the problem lies somewhere there, but I don't know where to start debugging. Converting the text to NVARCHAR didn't do anything either.
Here's an example of one of the rows in data:
(2861357, 'Exclusion Program: NonProcurement; Excluding Agency: HHS; CT Code: Z; Exclusion Type: Prohibition/Restriction; SAM Number: S4MR3Q9FL;')
I was unable to find my issue, but I ended up using QuerySets rather than running an UPDATE query.