SQL question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

SQL question

one question on my assignment says: write an SQL statement to create a table named 'countries' including columns: country_id, country_name and region_id which already exists. (2 marks) how do I create a table which already exists? what I have written is: CREATE TABLE countries (country_id INT (8), country_name CHAR (16), region_id INT(8)); is this correct?

6th Feb 2017, 8:19 PM
Jahva
Jahva - avatar
6 Answers
+ 24
Maybe use drop table countries to completely remove the existing table. Then you can make a new table of that name. I would suggest varchar2 instead of char :/
7th Feb 2017, 2:37 AM
Frost
Frost - avatar
+ 5
I read it as the columns already exist. Not the table. I would ask the teacher for claification. If the table containing the columns already exists then SELECT * INTO countries FROM existingTable Obviously replace * with column names
6th Feb 2017, 10:00 PM
jay
jay - avatar
+ 1
best way is just practice on Real time servers
21st Jun 2017, 6:19 PM
Kumar Rahul
Kumar Rahul - avatar
+ 1
better to check on syntaxes SQL>set server output on;
22nd Jun 2017, 3:36 PM
Kumar Rahul
Kumar Rahul - avatar
0
the statement you created is correct, you can make use of varchar2 instead of char. if you want to retain the existing table, then you can opt for rename command , and rename the existing table and create yours.so that you will not lose any data from the existing table.
7th Feb 2017, 4:18 AM
mahendra k
mahendra k - avatar
0
google it broo...
8th Feb 2017, 5:39 AM
Muhammad Ali
Muhammad Ali - avatar