Knowee
Questions
Features
Study Tools

Write a SQL script that creates a table users following these requirements:With these attributes:id, integer, never null, auto increment and primary keyemail, string (255 characters), never null and uniquename, string (255 characters)If the table already exists, your script should not failYour script can be executed on any database

Question

Write a SQL script that creates a table users following these requirements:With these attributes:id, integer, never null, auto increment and primary keyemail, string (255 characters), never null and uniquename, string (255 characters)If the table already exists, your script should not failYour script can be executed on any database

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a SQL script that creates a table named 'users' with the specified attributes:

CREATE TABLE IF NOT EXISTS users (
    id INT AUTO_INCREMENT,
    email VARCHAR(255) NOT NULL UNIQUE,
    name VARCHAR(255),
    PRIMARY KEY (id)
);

This script will not fail if the table already exists because of the IF NOT EXISTS clause. The id field is an integer, auto-incremented, and is the primary key. The email field is a string that can hold up to 255 characters, cannot be null, and must be unique. The name field is a string that can hold up to 255 characters.

This problem has been solved

Similar Questions

Charles is developing a travel booking system to manage customers, bookings, and payments. The system needs to handle three main types of data: CUSTOMERS, BOOKINGS, and PAYMENTS. To perform this the user needs to create the following tables with the mentioned constraints: symbol refers to the primary key NN refers to Not NULL After creating the tables, Charles needs to:Alter the CUSTOMERS table to change the primary key to Email to ensure each customer is uniquely identified by their email address.Drop the primary key from the BOOKINGS table as it is no longer required.Note: The user must write only the query to create, alter, and drop the table. The query to display the description of the table is already given.Input format :No console inputOutput format :The output displays the successful table creation status and the structure of all three tablesRefer to the sample output.Sample test cases :Input 1 :Output 1 :Table CUSTOMERS created.Table BOOKINGS created.Table PAYMENTS created.Table CUSTOMERS altered.Table CUSTOMERS altered.Table BOOKINGS altered. Name Null? Type _____________ ___________ ________________ CUSTOMERID NOT NULL NUMBER FIRSTNAME VARCHAR2(100) LASTNAME VARCHAR2(100) EMAIL NOT NULL VARCHAR2(100) Name Null? Type ______________ ___________ ________________ BOOKINGID NOT NULL NUMBER CUSTOMERID NUMBER BOOKINGDATE DATE DESTINATION VARCHAR2(100) Name Null? Type ______________ ___________ _________ PAYMENTID NOT NULL NUMBER BOOKINGID NUMBER AMOUNT NUMBER PAYMENTDATE DATE TABLE_NAME COLUMN_NAME POSITION STATUS _____________ ______________ ___________ __________ CUSTOMERS EMAIL 1 ENABLED 1 row selected.

CREATE TABLE IF NOT EXISTS `new_record` ( `id` int(11) NOT NULL AUTO_INCREMENT, `trn_date` datetime NOT NULL, `name` varchar(50) NOT NULL, `age`int(11) NOT NULL, `submittedby` varchar(50) NOT NULL, PRIMARY KEY (`id`) );

Users+-------------+---------+| Column Name | Type |+-------------+---------+| user_id | int || user_name | varchar |+-------------+---------+user_id is the primary key (column with unique values) for this table.Each row of this table contains the name and the id of a user. Table: Register+-------------+---------+| Column Name | Type |+-------------+---------+| contest_id | int || user_id | int |+-------------+---------+(contest_id, user_id) is the primary key (combination of columns with unique values) for this table.Each row of this table contains the id of a user and the contest they registered into. Write a solution to find the percentage of the users registered in each contest rounded to two decimals.Return the result table ordered by percentage in descending order. In case of a tie, order it by contest_id in ascending order.The result format is in the following example. Example 1:Input: Users table:+---------+-----------+| user_id | user_name |+---------+-----------+| 6 | Alice || 2 | Bob || 7 | Alex |+---------+-----------+Register table:+------------+---------+| contest_id | user_id |+------------+---------+| 215 | 6 || 209 | 2 || 208 | 2 || 210 | 6 || 208 | 6 || 209 | 7 || 209 | 6 || 215 | 7 || 208 | 7 || 210 | 2 || 207 | 2 || 210 | 7 |+------------+---------+Output: +------------+------------+| contest_id | percentage |+------------+------------+| 208 | 100.0 || 209 | 100.0 || 210 | 100.0 || 215 | 66.67 || 207 | 33.33 |+------------+------------+Explanation: All the users registered in contests 208, 209, and 210. The percentage is 100% and we sort them in the answer table by contest_id in ascending order.Alice and Alex registered in contest 215 and the percentage is ((2/3) * 100) = 66.67%Bob registered in contest 207 and the percentage is ((1/3) * 100) = 33.33%

What do you mean by table? How can you create table in SQL?

Ben is developing a health monitoring app to track user activities and vital signs. The app needs to handle three main types of data: USERS, ACTIVITIES, and VITALSWrite the DDL statements to create the following tables with the mentioned constraints to handle the data: symbol refers to the primary key NN refers to Not NULL After creating the tables, Ben needs to:Alter the USERS table to change the primary key to Email to ensure uniqueness based on email addresses.Drop the primary key from the ACTIVITIES table as it is no longer required.Note: The user must write only the query to create and alter the table. The query to display the description of the table is already given.

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.